您的当前位置:首页knife4j配置使用直接拷贝即可
knife4j配置使用直接拷贝即可
来源:锐游网
废话我就不多说了,直接上maven依赖
<!-- knife4j接口文档 -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
然后写一个配置类Knife4jConfig,为了避免导错包,把包也给你们了
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.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class Knife4jConfig {
@Bean(value = "defaultApi2")
public Docket defaultApi2() {
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.title("xxx接口说明")
.description("xxx接口描述")
.termsOfServiceUrl("http://www.xx.com/")
.contact(new Contact("xxx公司", "http://xxx.com/", "xxx@xxx.com"))
.version("1.0")
.build())
//分组名称
.groupName("2.X版本")
.select()
//这里指定Controller扫描包路径
.apis(RequestHandlerSelectors.basePackage("com.xxx.controller"))
.paths(PathSelectors.any())
.build();
return docket;
}
}
运行项目访问 http://localhost:8080/doc.html
因篇幅问题不能全部显示,请点此查看更多更全内容