标签:一个用户 des ice fse desc ring import service context
1)首先编辑pom.xml添加依赖
<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>
2)创建Swagger配置文件
package pro.kkpai.springbootswagger.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket RestApi(){ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("pro.kkpai.springbootswagger.controller")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() //标题 .title("这是Swagger的RESTFul API") //描述 .description("一个用户管理系统的RESTFul API") //联系方式 .contact(new Contact("kkpai", "https://kkpai.pro", "whatisnicedream@qq.com")) //服务条款url .termsOfServiceUrl("https://kkpai.pro")
//版本 .version("1.0") .build(); } }
3)Controller层类添加注解
@Api
未完。。。
Spring Boot 整合 swagger2 自动生成 RESTFul API 文档
标签:一个用户 des ice fse desc ring import service context
原文地址:https://www.cnblogs.com/1x11/p/9736173.html