1.15、Spring Boot 2.x 集成 Swagger UI

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的更多相关文章

  1. Spring boot 多模块项目 + Swagger 让你的API可视化

    Spring boot 多模块项目 + Swagger 让你的API可视化 前言 手写 Api 文档的几个痛点: 文档需要更新的时候,需要再次发送一份给前端,也就是文档更新交流不及时. 接口返回结果不 ...

  2. Spring Boot项目简单上手+swagger配置+项目发布(可能是史上最详细的)

    Spring Boot项目简单上手+swagger配置 1.项目实践 项目结构图 项目整体分为四部分:1.source code 2.sql-mapper 3.application.properti ...

  3. 9、Spring Boot 2.x 集成 Thymeleaf

    1.9 Spring Boot 2.x 集成 Thymeleaf 完整源码: Spring-Boot-Demos 1.9.1 在pom中引入依赖 <dependency> <grou ...

  4. 在Abp中集成Swagger UI功能

    在Abp中集成Swagger UI功能 1.安装Swashbuckle.Core包 通过NuGet将Swashbuckle.Core包安装到WebApi项目(或Web项目)中. 2.为WebApi方法 ...

  5. spring boot / cloud (三) 集成springfox-swagger2构建在线API文档

    spring boot / cloud (三) 集成springfox-swagger2构建在线API文档 前言 不能同步更新API文档会有什么问题? 理想情况下,为所开发的服务编写接口文档,能提高与 ...

  6. Spring Boot HikariCP 一 ——集成多数据源

    其实这里介绍的东西主要是参考的另外一篇文章,数据库读写分离的. 参考文章就把链接贴出来,里面有那位的代码,简单明了https://gitee.com/comven/dynamic-datasource ...

  7. Spring Boot系列——如何集成Log4j2

    上篇<Spring Boot系列--日志配置>介绍了Spring Boot如何进行日志配置,日志系统用的是Spring Boot默认的LogBack. 事实上,除了使用默认的LogBack ...

  8. 【ELK】4.spring boot 2.X集成ES spring-data-ES 进行CRUD操作 完整版+kibana管理ES的index操作

    spring boot 2.X集成ES 进行CRUD操作  完整版 内容包括: ============================================================ ...

  9. 14、Spring Boot 2.x 集成 Druid 数据源

    14.Spring Boot 2.x 集成 Druid 数据源 完整源码: Spring-Boot-Demos

随机推荐

  1. Xamarin.Forms FlyoutIcon 不显示(not shown)

    升级了VS2019到16.4版本,然后默认创建了一个Xamarin Shell程序 结果运行后是这个样子 难道不应该是这个样子吗? 百了个度一晚上没解决,资料本身就少,再就是提示设置FlyoutIco ...

  2. 【牛客网】Idol Master

    [牛客网]Idol Master 也是一道网络流解线性规划 不过需要从小于号的那边解 限制是\(a \leq \sum_{i = 1}^{k} x_{i}\leq b\) 其中\(0 \leq x_{ ...

  3. “无法改变的设计”——浅谈Java中的final关键字

    在Java中,final关键字可以用来修饰类.变量(包括成员变量和局部变量).方法,下面从这三个方面分别说明. final方法 当一个方法被final修饰时,表明这个方法不能被子类重写. 下面程序试图 ...

  4. 验证码处理+cookie模拟登录

    一.背景 相关博文:https://www.jianshu.com/p/9fce799edf1e https://blog.csdn.net/h19910518/article/details/793 ...

  5. 初始STM32

    主要内容: 1.什么是STM32 STM32有什么 STM32怎么选型号 一:什么是STM32 ST— 意法半寻体,是一个公司名,即SOC厂商(ARM是IP厂商,STM32中内核由ARM设计,外设例如 ...

  6. 使用Duilib开发Windows软件(2)——控件的基本介绍

    XML 先学习xml https://www.w3cschool.cn/xml/xml-xml-tutorialhc4o1t5m.html 控件 上图是我们下载的NIM_Duilib_Framewor ...

  7. 【规律】Cunning Friends

    Cunning Friends 题目描述 Anthony and his friends Ben and Chris decided to play a game. They have N piles ...

  8. 将迁移学习用于文本分类 《 Universal Language Model Fine-tuning for Text Classification》

    将迁移学习用于文本分类 < Universal Language Model Fine-tuning for Text Classification> 2018-07-27 20:07:4 ...

  9. (一)Lucene简介以及索引demo

    一.百度百科 Lucene是apache软件基金会4 jakarta项目组的一个子项目,是一个开放源代码的全文检索引擎工具包,但它不是一个完整的全文检索引擎,而是一个全文检索引擎的架构,提供了完整的查 ...

  10. 八、wepy代码规范

    变量与方法尽量使用驼峰式命名,并且注意避免使用$开头. 以$开头的标识符为WePY框架的内建属性和方法,可在JavaScript脚本中以this.的方式直接使用,具体请参考API文档. 小程序入口.页 ...