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. Docker下搭建mongodb副本集

    背景 有需求需要对mongodb做一个容灾备份.根据官网,发现mongodb最新版本(4.0)已经抛弃了主从模式而采用副本集进行容灾.副本集的优势在于:"有自动故障转移和恢复特性,其任意节点 ...

  2. 斜率优化dp学习笔记 洛谷P3915[HNOI2008]玩具装箱toy

    本文为原创??? 作者写这篇文章的时候刚刚初一毕业…… 如有错误请各位大佬指正 从例题入手 洛谷P3915[HNOI2008]玩具装箱toy Step0:读题 Q:暴力? 如果您学习过dp 不难推出d ...

  3. 关于php发送邮件(PHPmailer)的傻瓜式操作

    首先打开QQ邮箱(此处我们以QQ邮箱为例) 点击设置里面的账户开启pop3和smtp(此处需要用到绑定的手机号进行短信或QQ安全中心动态码进行验证) 接着复制以下email代码 //发送邮件 publ ...

  4. Django Simple Captcha的使用

    Django Simple Captcha的使用 1.下载Django Simple Captcha django-simple-captcha官方文档地址 http://django-simple- ...

  5. 少儿编程Scratch第四讲:射击游戏的制作,克隆的奥秘

    上周的宇宙大战射击游戏中,我们只完成了宇宙飞船发射子弹的部分.还未制作敌对方.这周制作了敌方-飞龙,飞龙随机在屏幕上方出现,如果被子弹打中,则得分,飞龙和子弹都消失. 敌方:飞龙:计分. 目的 目的: ...

  6. MyBatis 源码篇-MyBatis-Spring 剖析

    本章通过分析 mybatis-spring-x.x.x.jar Jar 包中的源码,了解 MyBatis 是如何与 Spring 进行集成的. Spring 配置文件 MyBatis 与 Spring ...

  7. mybaits实现oracle批量新增数据,回填主键

    项目有需求,百度了很久,反正他们说的方法,我都没成功,我也不知道是不是我写代码的姿势不正确,没办法只能自己想法子了 我们这个项目用到了通过Mapper,通用Mapper里通过OracleProvide ...

  8. (七)freemarker的基本语法及入门基础

    一.freemarker模板文件(*.ftl)的基本组成部分 1. 文本:直接输出的内容部分        2. 注释:不会输出的内容,格式为<#--  注释内容  -->         ...

  9. C# Winform 设置窗口打开的特效

    https://www.cnblogs.com/mq0036/p/6421946.html using System.Runtime.InteropServices; public class Win ...

  10. Abp 领域事件简单实践 <三> 自定义事件

    熵片用到的  EntityCreatedEventData<TEntity>,继承自EventData. 我们可以自定义事件: public class TestEvent: EventD ...