1、引入jar包
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency>
2、增加配置
package com.inspur.api.gd.projectbuilding.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; /** * @Description swagger配置类 * @Author chendeming * @Date 2021/5/4 * @Version 1.0 **/ @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) //是否开启 (true 开启 false隐藏。生产环境建议隐藏) //.enable(false) .select() //扫描的路径包,设置basePackage会将包下的所有被@Api标记类的所有方法作为api .apis(RequestHandlerSelectors.basePackage("扫包路径")) //指定路径处理PathSelectors.any()代表所有的路径 .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { Contact contact = new Contact("归属组织", "", ""); return new ApiInfoBuilder() //设置文档标题(API名称) .title("文档主题") //文档描述 .description("文档说明") //联系方式 .contact(contact) //版本号 .version("1.0.0") .build(); } }
3、快速上手demo
参数说明:https://blog.csdn.net/qq_39393671/article/details/103307690
返回DTO:https://blog.csdn.net/shangcunshanfu/article/details/100838687