springboot 整合swagger-ui
一、添加maven依赖
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger2</artifactId>
- <version>2.7.0</version>
- </dependency>
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger-ui</artifactId>
- <version>2.7.0</version>
- </dependency>
二、添加swagger配置类
- package com.system;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.web.context.request.async.DeferredResult;
- import springfox.documentation.builders.ApiInfoBuilder;
- import springfox.documentation.builders.PathSelectors;
- import springfox.documentation.builders.RequestHandlerSelectors;
- import springfox.documentation.service.ApiInfo;
- import springfox.documentation.spi.DocumentationType;
- import springfox.documentation.spring.web.plugins.Docket;
- @Configuration
- public class Swagger2Config {
- @Bean
- public Docket createRestApi() {
- return new Docket(DocumentationType.SWAGGER_2) //
- .genericModelSubstitutes(DeferredResult.class) //
- .useDefaultResponseMessages(false) //
- .forCodeGeneration(true) //
- .apiInfo(apiInfo()) //
- .pathMapping("/")//
- .select() //
- .apis(RequestHandlerSelectors.basePackage("com.controller")) //这边放你们的controller的包的位置
- .paths(PathSelectors.any()) //
- .build(); //
- }
- private ApiInfo apiInfo() {
- return new ApiInfoBuilder() //
- .title("swagger构建api文档") //
- .description("restfun风格") //
- .termsOfServiceUrl("https://github.com/springfox/springfox-demos") //
- .version("1.0") //
- .build();
- }
- }
三、springboot添加注解
四、一个测试用例
- @ApiOperation(value = "用户注册", notes = "用户注册", httpMethod = "POST")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "name", value = "用户昵称", required = true, dataType = "string",paramType = "query"),
- @ApiImplicitParam(name = "account", value = "账号", required = true, dataType = "string",paramType = "query"),
- @ApiImplicitParam(name = "pwd", value = "密码", required = true, dataType = "string",paramType = "query"),
- @ApiImplicitParam(name = "rePwd", value = "确认密码", required = true, dataType = "string",paramType = "query")
- })
一个注册的controller上面添加以上配置就可以了
swagger页面的访问路径 ip:port/swagger-ui.html
里面的要填的参数,上面配置的name会自动映射到controller里面名称相同的参数。
springboot 整合swagger-ui的更多相关文章
- SpringBoot整合Swagger和Actuator
前言 本篇文章主要介绍的是SpringBoot整合Swagger(API文档生成框架)和SpringBoot整合Actuator(项目监控)使用教程. SpringBoot整合Swagger 说明:如 ...
- 【SpringBoot | Swagger】SpringBoot整合Swagger
SpringBoot整合Swagger 1. 什么是Swagger Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.简单说就是项目跑起来了, ...
- SpringBoot 整合swagger
springBoot 整合swagger 1.pom.xml 配置 <dependency> <groupId>io.springfox</groupId> < ...
- springboot 集成swagger ui
springboot 配置swagger ui 1. 添加依赖 <!-- swagger ui --> <dependency> <groupId>io.sprin ...
- springboot整合swagger。完爆前后端调试
web接口开发时在调试阶段最麻烦的就是参数调试,前端需要咨询后端.后端有时候自己也不是很了解.这时候就会造成调试一次接口就需要看一次代码.Swagger帮我们解决对接的麻烦 springboot接入s ...
- SpringBoot整合Swagger测试api构建
@Author:SimpleWu 什么是Swagger? Swagger是什么:THE WORLD'S MOST POPULAR API TOOLING 根据官网的介绍: Swagger Inspec ...
- TP框架整合Swagger UI接口文档
1.下载swagger ui:http://swagger.io/swagger-ui/: 2.在应用目录里新建一个目录xxx:如图 3.解压后把dist目录的所有文件拷贝到新建的目录里面: 4.在新 ...
- SpringBoot整合swagger
Swagger使用 Swagger有什么用? swagger是一个流行的API开发框架,这个框架以“开放API声明”(OpenAPI Specification,OAS)为基础, 对整个API的开发周 ...
- SpringBoot整合Swagger实战
源码地址:https://github.com/laolunsi/spring-boot-examples 目前SpringBoot常被用于开发Java Web应用,特别是前后端分离项目.为方便前后端 ...
- springboot入门系列(二):SpringBoot整合Swagger
上一篇<简单搭建SpringBoot项目>讲了简单的搭建SpringBoot 项目,而 SpringBoot 和 Swagger-ui 搭配在持续交付的前后端开发中意义重大,Swagger ...
随机推荐
- Android开发(十七)——关闭中间activity
参考: http://java--hhf.iteye.com/blog/1826880
- 重定向如何携带cookie
起因 最近在做微信开放平台,需要给第三方入住,而且入住方都有自己的二级域名.做过微信开发的人都知道,坑爹的是微信并不支持这种二级域名的方式,所以用一个域名专门来处理. 问题 然后由于采用了一个专门的域 ...
- CentOs 6.x 升级 Python 版本【转】
在CentOS 6.X 上面安装 Python 2.7.X CentOS 6.X 自带的python版本是 2.6 , 由于工作需要,很多时候需要2.7版本.所以需要进行版本升级.由于一些系统工具和服 ...
- Spring Session Redis
http://www.infoq.com/cn/articles/Next-Generation-Session-Management-with-Spring-Session
- 【HTTPS】自签CA证书 && nginx配置https服务
首先,搭建https服务肯定需要一个https证书.这个证书可以看做是一个应用层面的证书.之所以这么说是因为https证书是基于CA证书生成的.对于正式的网站,CA证书需要到有资质的第三方证书颁发机构 ...
- Java知多少(8)类库及其组织结构
Java 官方为开发者提供了很多功能强大的类,这些类被分别放在各个包中,随JDK一起发布,称为Java类库或Java API. API(Application Programming Interfac ...
- 【转】WPF自定义控件与样式(3)-TextBox & RichTextBox & PasswordBox样式、水印、Label标签、功能扩展
一.前言.预览 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等. 本文主要是对文本输入控件进行样式开发,及相关扩展功能开发,主要内容包括: 基本文 ...
- Android Demos
SDK Manager 下载demo后,可以到SDK目录下面找 例如 C:\Program Files (x86)\Java\adt-bundle-windows-x86\sdk\samples\ ...
- 关于tomcat7服务下面js无法获取JSESSIONID的cookie信息
http://tomcat.apache.org/tomcat-5.5-doc/config/context.html Does anyone know what changed in the con ...
- Tetrahedron based light probe interpolation(基于四面体的Light Probe插值)
在当前的游戏引擎中,使用Light Probe来计算全局环境光对于动态物体的影响是一种很主流的方法.在预处理阶段生成完场景的Light Probe之后,传统的方法采用查找最近的8个相邻的Probe然后 ...