引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided </scope>
</dependency>
<!--mybatis-plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<scope>provided </scope>
</dependency>
<!--lombok用来简化实体类:需要安装lombok插件-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided </scope>
</dependency>
<!--swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<scope>provided </scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<scope>provided </scope>
</dependency>
书写配置类
@Bean
public Docket webApiConfig() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("webApi")
.apiInfo(webApiInfo())
.select()
.paths(Predicates.not(PathSelectors.regex("/admin/.*")))
.paths(Predicates.not(PathSelectors.regex("/error.*")))
.build();
}
private ApiInfo webApiInfo() {
return new ApiInfoBuilder()
.title("网站-课程中心API文档")
.description("本文档描述了课程中心微服务接口定义")
.version("1.0")
.contact(new Contact("starcpdk", "http://atguigu.com", "2381510397@qq.com"))
.build();
}
主springboot项目配置文件中添加注解@ComponentScan(“com.starcpdk.edu”)为了能够扫描到外面的包
使用方法
在controller中添加如下注解
@Api(description = "xxx") //添加到类之前 ,对该controller的 功能进行描述
@ApiOperation(value = "xxx") //添加到方法前面 , 对此接口的功能描述
@ApiParam("xxx") // 添加到参数前面 , 对参数进行描述
@ApiModelProperty(value = "xxxx") // 添加到实体类中的属性前对该属性进行描述
@ApiModelProperty(value = "xxx", example = "xxx") // 描述参数示例