15、Spring Boot 2.x 集成 Swagger UI
1.15、Spring Boot 2.x 集成 Swagger UI
- 完整源码: Spring-Boot-Demos
1.15.1 pom文件添加swagger包
<swagger2.version>2.8.0</swagger2.version>
……
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger2.version}</version>
</dependency>
1.15.2 添加Swagger2Config配置文件
package com.qm.products.prodmp.web.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.List;
/**
* @Description swagger ui 配置文件
* @Author hw
* @Date 2018/11/21 11:52
* @Version 1.0
*/
@Configuration
@ConditionalOnProperty(prefix = "swagger", value = {"enable"}, havingValue = "true") // 配置文件配置是否启动swagger配置文件
@EnableSwagger2 // 启用Swagger2
public class Swagger2Config {
@Bean
public Docket createRestApi() {
ParameterBuilder tokenParameter = new ParameterBuilder();
List<Parameter> params = new ArrayList<Parameter>();
params.add(tokenParameter.name("Authorization").description("授权Token").modelRef(new ModelRef("string")).parameterType("header").required(false).build());
return new Docket(DocumentationType.SWAGGER_2)
.globalOperationParameters(params)
.apiInfo(apiInfo())
.select()
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Spring Boot 2.x RESTful APIs")
.version("1.0")
.build();
}
}
1.15.3 Application类加入@EnableSwagger2注解开启swagger
@EnableSwagger2
@SpringBootApplication
public class SpringBootRestfulApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootRestfulApplication.class, args);
}
}
1.15.4 使用。
- 方法
@GetMapping("abnormal-pre")
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "string", paramType = "header")
})
public BaseRestResponse getAbnormalPre(@RequestParam String startDate, @RequestParam String endDate) {
List<AbnormalPreDTO> abnormalPreDTOS = onlineService.getAbnormalPre(startDate, endDate);
return BaseRestResponse.ok(abnormalPreDTOS);
}
@ApiOperation(value = "模糊搜索本公司用户 用户名/邮箱")
public BaseRestResponse fuzzySearchUsers(@RequestParam String param) {
- class
@RestController
@Api(tags = "Admin权限资源管理")
@RequestMapping("authority")
public class AuthorityController {
1.15.5 UI
访问 : http://localhost:8080/swagger-ui.html,就可以看到效果了。
15、Spring Boot 2.x 集成 Swagger UI的更多相关文章
- Spring boot 多模块项目 + Swagger 让你的API可视化
Spring boot 多模块项目 + Swagger 让你的API可视化 前言 手写 Api 文档的几个痛点: 文档需要更新的时候,需要再次发送一份给前端,也就是文档更新交流不及时. 接口返回结果不 ...
- Spring Boot项目简单上手+swagger配置+项目发布(可能是史上最详细的)
Spring Boot项目简单上手+swagger配置 1.项目实践 项目结构图 项目整体分为四部分:1.source code 2.sql-mapper 3.application.properti ...
- 9、Spring Boot 2.x 集成 Thymeleaf
1.9 Spring Boot 2.x 集成 Thymeleaf 完整源码: Spring-Boot-Demos 1.9.1 在pom中引入依赖 <dependency> <grou ...
- 在Abp中集成Swagger UI功能
在Abp中集成Swagger UI功能 1.安装Swashbuckle.Core包 通过NuGet将Swashbuckle.Core包安装到WebApi项目(或Web项目)中. 2.为WebApi方法 ...
- spring boot / cloud (三) 集成springfox-swagger2构建在线API文档
spring boot / cloud (三) 集成springfox-swagger2构建在线API文档 前言 不能同步更新API文档会有什么问题? 理想情况下,为所开发的服务编写接口文档,能提高与 ...
- Spring Boot HikariCP 一 ——集成多数据源
其实这里介绍的东西主要是参考的另外一篇文章,数据库读写分离的. 参考文章就把链接贴出来,里面有那位的代码,简单明了https://gitee.com/comven/dynamic-datasource ...
- Spring Boot系列——如何集成Log4j2
上篇<Spring Boot系列--日志配置>介绍了Spring Boot如何进行日志配置,日志系统用的是Spring Boot默认的LogBack. 事实上,除了使用默认的LogBack ...
- 【ELK】4.spring boot 2.X集成ES spring-data-ES 进行CRUD操作 完整版+kibana管理ES的index操作
spring boot 2.X集成ES 进行CRUD操作 完整版 内容包括: ============================================================ ...
- 14、Spring Boot 2.x 集成 Druid 数据源
14.Spring Boot 2.x 集成 Druid 数据源 完整源码: Spring-Boot-Demos
随机推荐
- WIN10更换无线网卡后WIFI无法正常启用
这里根据自己经历提供几个方案: 首先我们要确定这两个地方正常(表示网卡能识别.驱动安装好:有无线开关没打开的朋友请出门右转): 方案一:万能的重启,不觉得麻烦的就多重启几遍.大力出奇迹! 方案二:然后 ...
- 剑指Offer(4)——替换空格
题目: 请实现一个函数,把字符串中的每个空格替换成"%20".例如输入“We are happy.”,则输出“We%20are%20happy.”. 思路: 如果按照顺序从前往后依 ...
- Linux下/etc/login.defs文件
/etc/login.defs文件定义了与/etc/password和/etc/shadow配套的用户限制设定.这个文件是需要的,缺失并不会影响系统的使用,但是也许会产生意想不到的错误. 如果/etc ...
- Html5+Mui前端框架,开发记录(一)
1.下载HBuilder X,地址:http://www.dcloud.io/hbuilderx.html,根据需求选择版本下载. Mui文档,地址:http://dev.dcloud.net.cn/ ...
- c#获取本月有哪些周六、周日
最近项目中有用到本月所有的周六,周日,特此分享一下! 算法思路:写一个循环,条件为本月开始日期.本月截至日期,通过循环获取第一个周六,加一天就是周日,每增加六天就是下一个周六,依次类推,循环到月末 代 ...
- string类型常用函数
一个字符串就是一个string类型数据,此类型变量我们可以把它看作一个只读数组,其元素是char变量,在这里我们来说下string类型的常用命令. 1.TocharArray():将此实例中的字符复制 ...
- 十一、微信小程序-var、let、const用法详解
let命令 基本用法 ES6 新增了let命令,用来声明变量.它的用法类似于var,但是所声明的变量,只在let命令所在的代码块内有效. { let a = 10; var b = 1; } a // ...
- 第三代PacBio测序技术的测序原理和读长
针对PacBio单分子测序——第三代测序技术的测序原理和读长 DNA基因测序技术从上世纪70年代起,历经三代技术后,目前已发展成为一项相对成熟的生物产业.测序技术的应用也扩展到了生物.医学.制 ...
- Google Drive 和 Dropbox 同步同一个文件夹目录
Dropbox 也是非常棒的同步工具,例如先进的增量上传或者更开放的 API 等.可是为什么不曾想过把 Google Drive 和 Dropbox 同时使用呢,我是说,让这两者同时云同步同一个文件 ...
- MiniUI学习笔记一【转】
MiniUI Api文档:http://miniui.com/docs/api/index.html 1.取组件值 传递form data,load发送 请求加载数据 <script type= ...