一、导入依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
二、统一返回结果
三、创建配置类
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createDocket(){
ApiInfoBuilder apiInfoBuilder=new ApiInfoBuilder();
ApiInfo apiInfo=apiInfoBuilder.title("项目接口文档").build();
Docket docket=new Docket(DocumentationType.SWAGGER_2);
docket.apiInfo(apiInfo);
docket.select().apis(RequestHandlerSelectors.any());
return docket;
}
四、生成接口文档
http://localhost:8080/swagger-ui.html