欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

基于 springboot 和 mybatis 的 RealWorld 后端项目实践之三:添加 swagger!

最编程 2024-07-16 15:16:36
...
package org.example.config; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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 { private static Logger log = LoggerFactory.getLogger(SwaggerConfig.class); @Bean public Docket createRestApi() { log.info("进入到swagger的配置中"); return new Docket(DocumentationType.SWAGGER_2) // 指定构建api文档的详细信息的方法:apiInfo() .apiInfo(apiInfo()) .groupName("groupxx") .select() // 指定要生成api接口的包路径,这里把controller作为包路径,生成controller中的所有接口 .apis(RequestHandlerSelectors.basePackage("org.example.controller")) .paths(PathSelectors.any()) .build(); } /** * 构建api文档的详细信息 * @return */ private ApiInfo apiInfo() { return new ApiInfoBuilder() // 设置页面标题 .title("Spring Boot集成Swagger2接口总览") // 设置接口描述 .description("Swagger接口") // 设置联系方式 .contact(new Contact("测试swagger","http://localhost:8080/","")) // 设置版本 .version("1.0") // 构建 .build(); } }

推荐阅读