项目中使用的是springboot2.0+swagger2作为接口文档。遇到一个问题,如何对接口做排序让看接口的更直观些呢。
在marven中增加
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.xiaoymin/swagger-bootstrap-ui -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
https://www.cnblogs.com/mydotnetforyou/p/11943252.html
关键一点swagger注解的使用
@ApiSort(value = 5):给接口排序
@ApiOperationSupport(order = 1):给接口里面的方法排序,如下:
@RestController
@RequestMapping(value = "/api/message")
@Api(tags = "接口-短信")
@ApiSort(value = 5)
@ApiIgnore()
public class MessageController {
@RequestMapping(value = "/ct", method = {RequestMethod.GET}, produces = {"application/json"})
@ApiOperation(value = "短信总数", notes = "获取短信总数")
@ApiOperationSupport(order = 1)
public Result CT() {
...
}
在接口上写上@ApiSort @ApiOperationSupport代表接口排序,
在原EnableSwagger2注解上增加@EnableSwaggerBootstrapUi注解
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfiguration {
//more...
}
不想接口在页面上显示可以使用注解@ApiIgnore()
如何使用增强功能
相关参考文章:swagger-bootstrap-ui 1.8.5 发布,Swagger增强UI实现
springboot+swagger2 如何给接口排序
http://localhost:8091/doc.html 查看本地swaggerui文档localhost:8091是项目地址
http://localhost:8091/swagger-ui.html 查看接口文档
https://github.com/xiaoymin/swagger-bootstrap-ui.git git地址