項(xiàng)目中使用的是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
關(guān)鍵一點(diǎn)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 = "短信總數(shù)", notes = "獲取短信總數(shù)")
@ApiOperationSupport(order = 1)
public Result CT() {
...
}
在接口上寫上@ApiSort @ApiOperationSupport代表接口排序,
在原EnableSwagger2注解上增加@EnableSwaggerBootstrapUi注解
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfiguration {
//more...
}
image.png
不想接口在頁面上顯示可以使用注解@ApiIgnore()
如何使用增強(qiáng)功能
image.png
image.png
相關(guān)參考文章:swagger-bootstrap-ui 1.8.5 發(fā)布,Swagger增強(qiáng)UI實(shí)現(xiàn)
springboot+swagger2 如何給接口排序
http://localhost:8091/doc.html 查看本地swaggerui文檔localhost:8091是項(xiàng)目地址
http://localhost:8091/swagger-ui.html 查看接口文檔
https://github.com/xiaoymin/swagger-bootstrap-ui.git git地址