配置Swagger

1 引入依赖包

 1 <dependency>
 2       <groupId>io.springfox</groupId>
 3       <artifactId>springfox-swagger2</artifactId>
 4       <version>2.7.0</version>
 5 </dependency>
 6 <dependency>
 7        <groupId>io.springfox</groupId>
 8        <artifactId>springfox-swagger-ui</artifactId>
 9        <version>2.7.0</version>
10 </dependency>

 

2 在config中添加配置类

 

 1 @Configuration
 2 @EnableSwagger2
 3 public class Swagger2Config {
 4 
 5     @Bean
 6     public Docket webApiConfig(){
 7         return new Docket(DocumentationType.SWAGGER_2)
 8                 .groupName("webApi")
 9                 .apiInfo(webApiInfo())
10                 .select()
11                 .build();
12 
13     }
14 
15     private ApiInfo webApiInfo(){
16 
17         return new ApiInfoBuilder()
18                 .title("网站-讲师API文档")
19                 .description("本文档描述了讲师服务接口定义")
20                 .version("1.0")
21                 .contact("填入数据")
22                 .build();
23     }
24 }

   这个配置类一般都是固定的, 我们只需要直接赋值粘贴使用即可, 对于一些描述性的东西, 我们按照要求填入就好

 

3 使用

  在相应的地方使用最基本的四个注解:

    @Api

    @ApiModel

    @ApiOperation

    @ApiParam

posted @ 2021-01-08 22:51  0龙行者0  阅读(79)  评论(0编辑  收藏  举报