Spring Boot:整合Swagger
1、先创建一个SpringBoot项目
其中application.properties文件中是创建项目时自动添加的配置。

2、添加相关maven依赖
<!--swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
3、添加配置类
package com.xffy.order.common.config; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration
@EnableSwagger2
public class SwaggerConfig
{
@Bean
public Docket createRestApi()
{
return new Docket(DocumentationType.SWAGGER_2).enable(true)
.apiInfo(apiInfo());
} private ApiInfo apiInfo()
{
return new ApiInfoBuilder()
.version("3.0.0")
.build();
}
}
4、添加控制器(我这里是调用service层之后查询了数据库,也可以在controller层直接做假数据)
package com.xffy.order.controller; import com.xffy.order.common.resp.CommonResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.xffy.order.service.IEmployeeService;
import com.xffy.order.model.Employee; import javax.annotation.Resource; import org.springframework.web.bind.annotation.RestController; @RestController
@RequestMapping("/employee")
@Api(value = "雇员信息控制器", tags = { "雇员信息接口" })
public class EmployeeController extends BaseController
{ @Resource
private IEmployeeService employeeService; @GetMapping("/page.do")
@ApiOperation(value = "分页查询")
public CommonResp list(@RequestParam Integer page, @RequestParam Integer pageCount)
{
return CommonResp.success(employeeService.selectListByPage(page, pageCount));
} @PostMapping("/add.do")
@ApiOperation(value = "新增")
@ApiImplicitParam(name = "employee", value = "employee对象", required = true)
public CommonResp add(@RequestBody Employee employee)
{
return toAjaxBoolean(employeeService.save(employee));
} @DeleteMapping("/delete.do")
@ApiOperation(value = "删除")
@ApiImplicitParam(name = "id", value = "主键ID", required = true)
public CommonResp delete(Long id)
{
return toAjaxBoolean(employeeService.removeById(id));
} @PutMapping("/edit.do")
@ApiOperation(value = "修改")
@ApiImplicitParam(name = "employee", value = "employee对象", required = true)
public CommonResp edit(@RequestBody Employee employee)
{
return toAjaxBoolean(employeeService.updateById(employee));
} @GetMapping("/list.do")
@ApiOperation(value = "根据ID查询")
@ApiImplicitParam(name = "id", value = "主键ID", required = true)
public CommonResp selectEmployeeById(int id)
{
return CommonResp.success(employeeService.getById(id));
} }
5、本地运行之后访问 http://localhost:8080/swagger-ui.html

Spring Boot:整合Swagger的更多相关文章
- Spring Boot初识(3)- Spring Boot整合Swagger
一.本文介绍 如果Web项目是完全前后端分离的话(我认为现在完全前后端分离已经是趋势了)一般前端和后端交互都是通过接口的,对接口入参和出参描述的文档就是Mock文档.随着接口数量的增多和参数的个数增加 ...
- Spring Boot整合Swagger报错:"this.condition" is null
前段时间看到群里有吐槽swagger整合问题,当时没仔细看,总以为是姿势不对. 这两天正好自己升级Spring Boot版本,然后突然出现了这样的一个错误: Caused by: java.lang. ...
- Spring Boot整合swagger使用教程
目录 Swagger的介绍 优点与缺点 添加swagger 1.添加依赖包: 2.配置Swagger: 3.测试 场景: 定义接口组 定义接口 定义接口请求参数 场景一:请求参数是实体类. 场景二:请 ...
- Spring boot整合Swagger
本文github位置:https://github.com/WillVi/springboot-swagger2-demo 环境准备 JDK版本:1.8 Spring boot版本:1.5.16 Sw ...
- Swagger Learing - Spring Boot 整合swagger
学习了一下swagger. 这是编写的Demo 源码 https://github.com/AmberBar/Learning/tree/master/swagger-learning/swagger ...
- spring mvc ,spring boot 整合swagger
https://blog.csdn.net/qq_35992900/article/details/81274436
- Spring Boot初识(4)- Spring Boot整合JWT
一.本文介绍 上篇文章讲到Spring Boot整合Swagger的时候其实我就在思考关于接口安全的问题了,在这篇文章了我整合了JWT用来保证接口的安全性.我会先简单介绍一下JWT然后在上篇文章的基础 ...
- Spring Kafka和Spring Boot整合实现消息发送与消费简单案例
本文主要分享下Spring Boot和Spring Kafka如何配置整合,实现发送和接收来自Spring Kafka的消息. 先前我已经分享了Kafka的基本介绍与集群环境搭建方法.关于Kafka的 ...
- spring boot整合Swagger2
Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化RESTful风格的 Web 服务.总体目标是使客户端和文件系统作为服务器以同样的速度来更新.文件的方法,参数和模型紧密集成到服务器 ...
- Spring Boot整合JPA、Redis和Swagger2
好久没有总结了,最近也一直在学习.今天就把spring boot与其它技术的整合做个小总结,主要是jpa.redis和swagger2.公司里有用到这些,整合起来也很简单. 首先,新建一个Spring ...
随机推荐
- Redis4.0.14 迁槽失败
线上一个redis集群中主节点使用的内存达到了9.78g,按照redis单个实例最大内存不要超出10g的规范,扩容操作就放在了今天晚上进行.因为之前redis迁槽都是采用 redis-trib.rb ...
- 2021.08.16 P1363 幻象迷宫(dfs,我感受到了出题人浓浓的恶意)
2021.08.16 P1363 幻象迷宫(dfs,我感受到了出题人浓浓的恶意) P1363 幻象迷宫 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 题意: 幻象迷宫可以认为是无限 ...
- python中常用内置函数和关键词
Python 常用内置函数如下: Python 解释器内置了很多函数和类型,您可以在任何时候使用它们.以下按字母表顺序列出它们. 1. abs()函数 返回数字的绝对值. print( abs(-45 ...
- Fauce:Fast and Accurate Deep Ensembles with Uncertainty for Cardinality Estimation 论文解读(VLDB 2021)
Fauce:Fast and Accurate Deep Ensembles with Uncertainty for Cardinality Estimation 论文解读(VLDB 2021) 本 ...
- 小米手机简单 ROOT教程(百分百成功)
大家都知道啊,由于小米自带的换机软件不支持一些应用数据的还原,所以需要使用钛备份来还原应用和数据.但是钛备份需要root才能用,因为有些机器刚出没多久,第三方的recovery也没有,所以需要找到一种 ...
- 2. flddler响应显示乱码问题解决方案
Fiddler是一款强大Web调试工具,它能记录所有客户端和服务器的HTTP请求. Fiddler启动的时候,默认IE的代理设为了127.0.0.1:8888,而其他浏览器是需要手动设置.但是一开始使 ...
- javaScript中Number数字类型方法入门
前言 Number和Math都属于JavaScript中的内置对象,Number数字类型作为基础数据类型,我们在开发过程中会经常用到,包括数字精度的格式化,还有字符串转换成数字等操作. Number数 ...
- Azure Terraform(十一)Azure DevOps Pipeline 内的动态临时变量的使用
思路浅析 在我们分析的 Azure Terraform 系列文中有介绍到关于 Terraform 的状态文件远程存储的问题,我们在 Azure DevOps Pipeline 的 Task Job ...
- 宝藏发现之API接口高效协作神器Apifox
概述 背景 Apifox官方地址 https://www.apifox.cn/ 前面文章我们已经围绕微服务展开,缺少一个关键前置流程,那就是API接口设计,而在API接口设计开始前本篇先推荐一个非常好 ...
- 虚拟机(Vmvare)与配置,得到一台学习机
准备: 1.Vmvare 2.CentOS7.4镜像 安装与配置操作系统: 1.配置虚拟机上网 2.配置静态ip地址 开始安装 1. 2.直接下一步选择我们准备好的镜像,然后下一步 3.修改虚拟机的名 ...