作用
方便测试接口
代码
@Configuration
public class Swagger2Configuration {
//版本
public static final String VERSION = "1.0.0";
//控制开关
@Value("${blog-swagger-enable}")
private boolean enable;
/**
* 接口前缀:mp
*
* @return
*/
@Bean
public Docket mpApi() {
return new Docket(DocumentationType.SWAGGER_2)
.enable(enable)
.apiInfo(mpApiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("xxxx.controller.portal"))
.paths(PathSelectors.any()) //可以根据url路径设置哪些请求加入文档,忽略哪些请求
.build()
.groupName("设置组名");
}
private ApiInfo mpApiInfo() {
return new ApiInfoBuilder()
.title("设置文档标题") //设置文档标题
.description("设置文档的描述") //设置文档的描述
.version(VERSION) //设置文档的版本信息->1.0.0 Version information
.build();
}