当前位置: 首页 > news >正文

如何给公司网站做优化什么是指数基金

如何给公司网站做优化,什么是指数基金,wordpress 评论次数,网页设计代码居中用 Swagger 实现接口文档 1.配置 Swagger1.1 添加 Swagger 依赖1.2 创建 Swagger 配置类 2.编写接口文档 在项目开发中,一般都是由前后端工程师共同定义接口,编写接口文档,之后大家根据这个接口文档进行开发、维护。为了便于编写和维护稳定&a…

用 Swagger 实现接口文档

  • 1.配置 Swagger
    • 1.1 添加 Swagger 依赖
    • 1.2 创建 Swagger 配置类
  • 2.编写接口文档

在项目开发中,一般都是由前后端工程师共同定义接口,编写接口文档,之后大家根据这个接口文档进行开发、维护。为了便于编写和维护稳定,可以使用 Swagger 来编写 API 接口文档,以提升团队的沟通效率。

下面演示如何在 Spring Boot 中继承 Swagger。

1.配置 Swagger

1.1 添加 Swagger 依赖

<!--Swagger依赖-->
<dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.9.2</version>
</dependency><!--Swagger-UI依赖 -->
<dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.9.2</version>
</dependency>

1.2 创建 Swagger 配置类

创建 Swagger 配置类,完成相关配置项,见以下代码:

package com.example.demo.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;/*** Swagger 配置类* 在与 Spring Boot 集成时,放在与 Application.java 同级的目录下*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {/*** 创建 API 应用* 本例采用指定扫描的包路径来定义指定要建立 API 的目录*/@Beanpublic Docket createRestApi() {return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage("com.example.demo.controller")).paths(PathSelectors.any()).build();}/*** 创建该 API 的基本信息(这些基本信息会展现在文档页面中)* 访问地址:http://项目实际地址/swagger-ui.html*/private ApiInfo apiInfo() {return new ApiInfoBuilder().title(" RESTful APIs").description("RESTful APIs").termsOfServiceUrl("http://localhost:8080/").contact("pipi").version("1.0").build();}
}
  • @Configuration:让 Spring 来加载该类配置。
  • @EnableSwagger2:启用 Swagger2.createRestApi 函数创建 Docket 的 Bean。
  • apiInfo():用来展示该 API 的基本信息。
  • select():返回一个 ApiSelectorBuilder 实例,用来控制哪些接口暴露给 Swagger 来展现。
  • apis(RequestHandlerSelectors.basePackage()):配置包扫描路径。Swagger 会扫描包下所有 Controler 定义的 API,并产生文档内容。如果不想产生 API,则使用注解 @ApiIgnore

2.编写接口文档

在完成上述配置后,即生成了文档,但是这样生成的文档主要针对请求本身,而描述自动根据方法等命名产生,对用户并不友好。所以,通常需要自己增加一些说明以丰富文档内容。可以通过以下注解来增加说明。

  • @Api:描述类/接口的主要用途。
  • @ApiOperation:描述方法用途,给 API 增加说明。
  • @ApiImplicitParam:描述方法的参数,给参数增加说明。
  • @ApiImplicitParams:描述方法的参数(Multi-Params),给参数增加说明。
  • @ApiIgnore:忽略某类/方法/参数的文档。

具体使用方法见以下代码:

package com.example.demo.controller;import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;@RestController
public class HelloWorldController {@ApiOperation(value = "hello", notes = "notes")@RequestMapping("/hello")public String hello() throws Exception {return "HelloWorld ,Spring Boot!";}// 使用该注解忽略这个 API@ApiIgnore@RequestMapping(value = "/ignoreApi")public String  ignoreApi() {return "HelloWorld ,Spring Boot!";}
}

完成上述代码后,启动项目,访问 http://localhost:8080/swagger-ui.html 就能看到所展示的 RESTful API 的页面,可以通过单击具体的 API 测试请求,来查看代码中配置的信息,以及参数的描述信息。

在这里插入图片描述
在这里插入图片描述

http://www.dinnco.com/news/50902.html

相关文章:

  • 哪里有做网站技术信息流广告案例
  • 漳平建设局网站网站营销策划
  • 青岛网络科技有限公司企业站seo报价
  • ubantu 编辑wordpress搜索seo优化托管
  • 企业简介模板pptseo前线
  • 成都网站建设 培训班网站建设公司哪个好呀
  • 建设部网站13清单克州seo整站排名
  • 知识付费商城源码seo推广方法
  • 著名的wordpress网站广州网络推广服务商
  • 南昌好的做网站的公司百度竞价点击神器
  • 太原顶呱呱做网站地址电话seo排名平台
  • 版权申请网站正规网站优化哪个公司好
  • 网站的图形拖拽验证码怎么做的建网站找哪个平台好呢
  • 重庆域名注册官网福州百度关键词优化
  • wordpress修改用户资料seo收费标准
  • 海外加速器免费seo网站自动推广
  • 桂林微信网站开发河北seo推广方案
  • 史志网站建设泉州网站关键词排名
  • it运维管理开封seo推广
  • 邢台高端网站建设北京seo培训机构
  • 邢台建设银行网站百度经验悬赏令
  • 鹿城做网站千锋教育北京校区
  • 做it题的网站微信推广方案
  • 网站屏蔽ip地址sem搜索
  • 包头网站优化优化大师电视版
  • 天猫商城入驻seo推广 课程
  • 申请自助建站英国搜索引擎
  • 无法与网站建立安全连接网站推广关键词工具
  • 视频制作软件电脑江门seo外包公司
  • 老域名做网站视频推广方案模板