依赖
复制代码
1
2
3
4
5
6
7
8
9
10
11
12<dependency> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> <version>1.5.18</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>knife4j-spring-boot-starter</artifactId> <version>3.0.2</version> </dependency>
config
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration; 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; @Configuration @EnableSwagger2 @EnableKnife4j @Import(BeanValidatorPluginsConfiguration.class) public class Knife4jConfig { private ApiInfo apiInfo(){ return new ApiInfoBuilder() .title("xxxx项目接口文档") .description("xxxx项目1.0的接口文档,仅限内部使用") .termsOfServiceUrl("xxxx项目域名") .contact(new Contact("作者","url","email")) .version("1.0") .build(); } @Bean public Docket defaultApi2() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) //分组名称 //.groupName("1.0版本") .select() //指定controller(接口)扫描的包路径 .apis(RequestHandlerSelectors.basePackage("com.xxx.controller")) .paths(PathSelectors.any()) .build(); } }
注解
复制代码
1
2
3
4
5@Api(tags = "订单接口") //标注在类上面 @ApiOperation("取消订单") // 标注在方法上面 // 还有其它注解,上面是最常用的
访问地址:localhost:port/doc.html (你的ip和端口)
上面的直接复制拿去改一下名字就能用,就是为了复制起来简单记录一下
最后
以上就是虚幻黑裤最近收集整理的关于丝袜哥Swagger-knife4j在线文档的全部内容,更多相关丝袜哥Swagger-knife4j在线文档内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复