集成SwaggerUI界面美化-knife4j
地址:https://doc.xiaominfo.com/knife4j/documentation/
FAQ:https://doc.xiaominfo.com/faq/knife4j-exception.html
- 引入Jar包 注意去掉swagger相关的包,不要单独引入
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.7</version>
</dependency>
- 配置类
@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {
@Bean(value = "admin")
public Docket defaultApi2() {
Docket docket=new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
//.title("swagger-bootstrap-ui-demo RESTful APIs")
.description("# swagger-bootstrap-ui-demo RESTFUL APIs")
.termsOfServiceUrl("http://www.xx.com/")
.contact("xx@qq.com")
.version("1.0")
.build())
//分组名称
.groupName("后台")
.select()
//这里指定Controller扫描包路径
.apis(RequestHandlerSelectors.basePackage("com.nft.controller.admin"))
.paths(PathSelectors.any())
.build();
return docket;
}
@Bean(value = "official")
public Docket defaultApi() {
Docket docket=new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.description("# swagger-bootstrap-ui-demo RESTFUL APIs")
.termsOfServiceUrl("http://www.xx.com/")
.contact("xx@qq.com")
.version("1.0")
.build())
//分组名称
.groupName("官网")
.select()
//这里指定Controller扫描包路径
.apis(RequestHandlerSelectors.basePackage("com.nft.controller.official"))
.paths(PathSelectors.any())
.build();
return docket;
}
}