1.pom.xml文件引入依赖
<!--knife4j-->
<!-- Knife4j和Swagger2不能同时引用 -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.8</version>
</dependency>
2.配置类Knife4jConfig.ava
@Configuration
@EnableSwagger2WebMvc
@EnableKnife4j
@ConfigurationProperties(prefix = "swagger.config")
public class Knife4jConfig {
@Bean(value = "API接口文档")
public Docket defaultApi2() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.title("API接口文档")
.description("# swagger-bootstrap-ui-demo RESTful APIs")
.termsOfServiceUrl("http://localhost:8888/swagger-ui.html")
.version("v2.0")
.build())
//分组名称
.groupName("2.X版本")
.select()
//这里指定Controller扫描包路径
.apis(RequestHandlerSelectors.basePackage("com.zky.music.controller"))
.paths(PathSelectors.any())
.build();
}
}
3.controller接口注解
类注解:
@Api(tags = "随便填 ")
方法注解:
@ApiOperation(value = "随便填 ")
即可使用,地址:localhost:8080/doc.html
其余注解不在赘述
1.pom.xml文件引入依赖
<!--Swagger2-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
2.配置类SwaggerConfig .java
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
Docket docket(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.zky.music.controller"))
.paths(PathSelectors.any())
.build().apiInfo(new ApiInfoBuilder()
.description("API文档")
.contact(new Contact("yuan",
"https://github.com/MJUniversity/xxxxxxx",
"2584278161@qq.com"))
.version("v1.0")
.title("API文档")
.license("Apache2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
.build());
}
}
3.controller接口注解
类注解:
@Api(tags = " 随便填")
方法注解:
@ApiOperation(value = "随便填 ")
即可使用,地址:localhost:8080/swagger-ui.html
其余注解不在赘述
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)