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
随机推荐
- JMeter接口自动化学习笔记(一)
实例教程:https://blog.csdn.net/kasijia/article/details/79405815 https://www.cnblogs.com/rd-ddddd/p/95782 ...
- 【AtCoder】diverta 2019 Programming Contest 2
diverta 2019 Programming Contest 2 A - Ball Distribution 特判一下一个人的,否则是\(N - (K - 1) - 1\) #include &l ...
- Centos7.x 安装libevent2.x
1.在http://libevent.org/下载libevent-2.1.8-stable.tar.gz 2.tar -zxvf libevent-2.1.8-stable.tar.gz 3.cd ...
- C++:链表(有头链表)
介绍 把链表分为无头链表和有头链表. 无头链表:所有的节点都包含了有效数据,上一篇文章中演示代码使用的就是无头链表. 有头链表:用一个固定的头节点来指代整个链表,所有的对象都挂在这个头节点下面,而头节 ...
- C++:顺序表类实现约瑟夫问题_密码不同
//.h #pragma once #include <iostream> using namespace std; #define MAXSIZE 100 template <cl ...
- ndarray笔记
Numpy的介绍 1. Ndarray:N-dimensional array, N维数组 2. 一种由相同类型的元素组成的多维数组,元素数量是事先指定好的 例:建立Ndarray多维数组 nd ...
- 数据库设计_ERMaster安装使用_PowerDesigner数据设计工具
数据库设计 1. 说在前面 项目开发的流程包括哪些环节 需求调研[需求调研报告]-- 公司决策层 (1) 根据市场公司需求分析公司是否需要开发软件来辅助日常工作 (2) 公司高层市场考察,市场分析,决 ...
- (一)Activiti简介
一.概念 Activiti项目是一项新的基于Apache许可的开源BPM平台,从基础开始构建,旨在提供支持新的BPMN 2.0标准,包括支持对象管理组(OMG),面对新技术的机遇,诸如互操作性和云架构 ...
- (五)CXF之添加拦截器
一.需求分析 webService中的拦截器类似于servlet的Filter过滤器.一般用于调用服务前后先调用拦截器的方法. 二.案例 本章案例是基于上一章节的基础上添加拦截器的 2.1 服务端添加 ...
- (三)springmvc之注解的基本使用
一.@Controller @Controller 标记一个类是Controller 二.RequestMapping 地址映射 2.1 Value的操作. 注解在类上面 (父) ...