1. 添加依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
2. 添加配置类
@Bean
public Docket api(){
ApiInfoBuilder builder = new ApiInfoBuilder();
builder.title("这是Swagger文档的标题")
.description("这是一份api说明文档")
.version("4.0");
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.chenghua.springscaffold.controllers"))
.paths(PathSelectors.any())
.build()
.apiInfo(builder.build());
}
?此处配置了文档的标题、描述文字、版本、Controller包地址、路径过滤。
3. 开启EnableSwagger2
@SpringBootApplication
@EnableSwagger2
public class Startup {
public static void main(String[] args) {
SpringApplication.run(Startup.class, args);
}
}
4. 查看效果
?
访问/swagger-ui.html即可查看效果?
|