1、之前使用的swagge版本,进行排序的时候发现,排序已经被废弃
<!--swagger2依赖 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!--swagger2-ui依赖-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
2、需要重新引入新的ui进行排序
<!--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>
3、在你的接口上面怎么加这个
@ApiSort(value = 5) //给接口排序 @ApiOperationSupport(order = 1) //给接口里面的方法排序 @ApiSort(value = 1) public class ADSchoolController { @GetMapping("/aaaa") @ApiOperationSupport(order = 2) //排序 public void getAdSchoolListWithPage(@RequestParam(value = "token", defaultValue = "") String token) { } @GetMapping("/bbbb") @ApiOperationSupport(order = 1) //排序 public void getAdSchoolListWithPage(@RequestParam(value = "token", defaultValue = "") String token) { } }
4、找到的swaggerconfig文件、增加红色这个
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
@Configuration
@EnableSwagger2
@ConditionalOnProperty(name = "spring.profiles.active", havingValue = "dev")
@EnableSwaggerBootstrapUI
public class Swagger2Config {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
.apis(RequestHandlerSelectors.basePackage("com.cuiyanet.business")).paths(PathSelectors.any()).build();
}
}
5、之后访问 http://127.0.0.1/doc.html 路径
6、刷新界面,你就发现你的接口已经排序成功了
7、还有一个加强版的,只需要引入下面这一个包,第4步添加的注解变成,@EnableKnife4j,排序解决
<!-- https://mvnrepository.com/artifact/com.github.xiaoymin/knife4j-spring-boot-starter -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.2</version>
</dependency>