当前位置:
首页 >
前端技术
> javascript
>内容正文
javascript
Springfox-swagger使用详解
生活随笔
收集整理的这篇文章主要介绍了
Springfox-swagger使用详解
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
Springfox-swagger使用详解
- 什么是Swagger?
- Swagger的具体使用
- 一、导入依赖
- 二、建立Swagger配置类
- 三、通过Swagger测试接口
- 引用
什么是Swagger?
是一个开源的API Doc的框架Swagger的具体使用
一、导入依赖
<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>二、建立Swagger配置类
@Configuration @EnableSwagger2 //开启swagger2 public class SwaggerConfig {@Beanpublic Docket docket(Environment environment){Profiles profiles = Profiles.of("dev");boolean enable = environment.acceptsProfiles(profiles); //根据当前开发环境来决定是否要运行swaggerreturn new Docket(DocumentationType.SWAGGER_2).groupName("InformationController") //我们通过建立多个Docket类并给不同的groupname区分不同人员的文档// 修改swagger-ui.html界面的基础显示信息.apiInfo(apiInfo())//判断是否是开发模式,来决定是否开启swagger2.enable(enable)// apis 配置扫描接口的方式.select().apis(RequestHandlerSelectors.basePackage("com.wyw.checkinsystem.Controller")) //限定扫描的Controller目录.paths(PathSelectors.ant("/loginstu")) //限定扫描的请求链接.build();//被Controller return的实体类都会显示在model中,我们也可以通过注释标注,为Models添加信息//同样,我们可以使用另外两个注释,为controller中的方法及其参数添加信息}private ApiInfo apiInfo(){Contact contact = new Contact("name", "", "");return new ApiInfo("Ostrich5yw Api Documentation","Api Documentation","1.0","urn:tos",contact,"Apache 2.0","http://www.apache.org/licenses/LICENSE-2.0",new ArrayList<VendorExtension>());}三、通过Swagger测试接口
我们通过Swagger可以直接填入数据请求来测试Controller中的接口 PS:进入http://localhost:端口号/swagger-ui.html查看swagger日志引用
本文根据遇见狂神说的Docker视频编写。
总结
以上是生活随笔为你收集整理的Springfox-swagger使用详解的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 增强中获取屏幕值的一句很实用代码…
- 下一篇: Spring security/Shir