引入
<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>
配置swagger配置类
@EnableSwagger2 @Configuration public class Swagger2Config { @Bean public Docket createRestApi(){ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.test.web")) //controller的根目录 .paths(PathSelectors.any()) //可以根据url路径设置哪些请求加入文档,忽略哪些请求 .build(); } public ApiInfo apiInfo(){ return new ApiInfoBuilder() .title("标题") .description("描述") .version("1.0.0") .termsOfServiceUrl("www.test.com") .build(); } }
controller 只需要配置相应说明文字即可
@Api(tags = {"类功能说明"})
@ApiOperation(value = "方法功能说明")