Java Api 文档
Swagger2
<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>
常用注解
@Api:controller类注解
@ApiOperation:controller类中方法注解
@ApiIgnore:忽略
@ApiParam:请求属性设置
配置注入
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com")) //要扫描的包名
.paths(PathSelectors.any()) //过滤路径
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Restful Api | 文档构建")
.description("更多Spring Boot相关文章请关注:http://www.xxx.com/")
.termsOfServiceUrl("http://www.xxx.com/")
.contact(new Contact("abc", "http://www.xxx.com/", "abc@163.com"))
.version("1.0")
.build();
}
}
通过.groupName("")
可以设置分组,每个分组对应一个Docket
实例,相关参见
knife4j
基于Spring Boot的增强文档:https://doc.xiaominfo.com/knife4j/
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.4</version>
</dependency>
---
纵使山重水复,亦会柳暗花明
sunqh1991@163.com
欢迎关注,互相交流