spring boot + swagger2
- 引入maven依赖:
springfox-swagger2是swagger核心代码;springfox-swagger-ui提供静态jsUI可视化页面
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.0</version>
</dependency>
- 启用swagger
package com.ssth.exchange.exsite; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger2.annotations.EnableSwagger2; @SpringBootApplication(scanBasePackages = { "com.ssth.exchange.exsite"})
@Configuration
@MapperScan("com.ssth.exchange.exsite.mapper")
@EnableSwagger2
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
使用@EnableSwagger2注解启用swagger
- 在接口中添加对应注解
package com.ssth.exchange.exsite.controller; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import com.ssth.exchange.exsite.controller.basic.ExsiteBaseController;
import com.ssth.exchange.exsite.controller.request.NavigationReq;
import com.ssth.exchange.exsite.controller.response.NavigationResp;
import com.ssth.exchange.exsite.controller.response.ResponseEntity;
import com.ssth.exchange.exsite.service.HomeService; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; /**
* @Description 首页控制器
* @author chengmuyu
* @date 2018年5月31日 下午2:31:12
*/
@RestController
@RequestMapping("/home")
@ResponseBody
@CrossOrigin
@Api(value="首页接口",consumes="application/json")
public class HomeController extends ExsiteBaseController { @Autowired
private HomeService homeService; /**
* @Description 获取导航列表
* @param nav 导航查询参数
* @return
*/
@RequestMapping(value = "list/nav",method = RequestMethod.POST)
@ApiOperation(value="获取导航列表", httpMethod = "POST", response = NavigationResp.class)
public ResponseEntity<List<NavigationResp>> listNavigation(@RequestBody NavigationReq nav) {
return ResponseEntity.successResponse(homeService.listNavigation(nav.getPid()));
}
}
- 实体声明定义
package com.ssth.exchange.exsite.controller.request; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; /**
* @Description 导航请求实体
* @author chengmuyu
* @date 2018年5月31日 下午3:04:05
*/
@ApiModel(value = "导航请求")
public class NavigationReq {
@ApiModelProperty(value = "导航父id,null表示查询一级目录")
private String pid;
}
- Swagger常用注解
swagger通过注解表明该接口会生成文档,包括接口名、请求方法、参数、返回信息的等等。
@Api:修饰整个类,描述Controller的作用
@ApiOperation:描述一个类的一个方法,或者说一个接口
@ApiParam:单个参数描述
@ApiModel:用对象来接收参数
@ApiProperty:用对象接收参数时,描述对象的一个字段
@ApiResponse:HTTP响应其中1个描述
@ApiResponses:HTTP响应整体描述
@ApiIgnore:使用该注解忽略这个API
@ApiError :发生错误返回的信息
@ApiImplicitParam:一个请求参数
@ApiImplicitParams:多个请求参数
spring boot + swagger2的更多相关文章
- Java | Spring Boot Swagger2 集成REST ful API 生成接口文档
Spring Boot Swagger2 集成REST ful API 生成接口文档 原文 简介 由于Spring Boot 的特性,用来开发 REST ful 变得非常容易,并且结合 Swagg ...
- spring boot☞Swagger2文档构建及单元测试
首先,回顾并详细说明一下在快速入门中使用的@Controller.@RestController.@RequestMapping注解.如果您对Spring MVC不熟悉并且还没有尝试过快速入门案例,建 ...
- (转) 增加 header 参数,spring boot + swagger2(springfox)
1 @Configuration 2 @EnableSwagger2 3 public class Swagger2 { 4 @Bean 5 public Docket createRestApi() ...
- Spring Boot Swagger2自动生成接口文档
一.简介 在当下这个前后端分离的技术趋势下,前端工程师过度依赖后端工程师的接口和数据,给开发带来了两大问题: 1.问题一.后端接口查看难:要怎么调用?参数怎么传递?有几个参数?参数都代表什么含义? 2 ...
- spring boot Swagger2(version=2.7.0) 注解@ApiImplicitParam的属性dataType值为”自定义泛型“应用
注解: @ApiImplicitParams @ApiImplicitParam name="需注解的API输入参数", value="接收参数的意义描述" ...
- Spring Boot(九)Swagger2自动生成接口文档和Mock模拟数据
一.简介 在当下这个前后端分离的技术趋势下,前端工程师过度依赖后端工程师的接口和数据,给开发带来了两大问题: 问题一.后端接口查看难:要怎么调用?参数怎么传递?有几个参数?参数都代表什么含义? 问题二 ...
- spring boot 2.x 系列——spring-boot 集成 Swagger2 打造在线接口文档
文章目录 一.Springfox 与 Swagger 简介 1.1 Springfox 1.2 Swagger 1.3 OpenApi.Swagger.Springfox的关系 二.spring bo ...
- Spring Boot 系列教程9-swagger-前后端分离后的标准
前后端分离的必要 现在的趋势发展,需要把前后端开发和部署做到真正的分离 做前端的谁也不想用Maven或者Gradle作为构建工具 做后端的谁也不想要用Grunt或者Gulp作为构建工具 前后端需要通过 ...
- 国内最全的Spring Boot系列之二
历史文章 <国内最全的Spring Boot系列之一> 视频&交流平台 SpringBoot视频:http://t.cn/R3QepWG Spring Cloud视频:http:/ ...
随机推荐
- Node初始以及环境搭建(Node01)
1. 相关概念 •什么是JavaScript? •一种遵守ECMAScript标准的脚本语言 •最初只能运行在浏览器端 •浏览器中的 JavaScript 可以做什么? •操作DOM:表单验证.动画 ...
- 【原创】大叔经验分享(90)linux服务器iowait和负载很高
# top top - 21:21:51 up 207 days, 1:30, 5 users, load average: 0.90, 0.79, 1.62 Tasks: 249 total, 1 ...
- 清空windows系统网络配置
清空windows系统网络配置 来源 https://www.cnblogs.com/lemon-rain/p/9569990.html 具体描述:qq,微信可用网,但其他不能用. 一.win+r ...
- 学习笔记-Rabin-Karp哈希
在数学一本通上看过这两人名字,现在又出现了... 思想: 用一个整数表示一个字符串 \(w_{str}\)=(\(a_0\) \(p^{n-1}\)+\(a_1\) \(p^{n-2}\)+...+\ ...
- 如何把Windows主机中的文件拉到centOS虚拟机中
如何把Windows主机中的文件拉到centOS虚拟机中 2017年02月19日 22:19:12 Ariel_lin2017 阅读数:6023 标签: vmware tools共享文件 之前写了 ...
- Java 之 泛型
一.泛型概述 集合中是可以存放任意对象的,只要把对象存储集合后,那么这时他们都会被提升成 Object 类型.当我们取出一个对象,并且进行相应的操作,这时必须采用类型转换. 先观察下面代码: publ ...
- ADF一个EO的事物提交周期
客户端通过传递键对象调用实体定义的findByPrimaryKey(),获得EO.ADF框架首先检查实体缓存, 如果在实体缓存中没有找到实体,就执行SQL SELECT查询,从数据库读取行.示例如下: ...
- SmartBinding工作原理分析
关于kbmMW SmartBinding,我翻译了作者写的几篇文章,其强大的绑定机制,将可视控制与各种数据源灵活绑定在一起,实现了类似DBEdit数据敏感控件的效果,可以及大的减少我们的代码,实现界面 ...
- openstack安装部署——计算服务(控制节点&计算节点)前言
1.前言Openstack计算服务通过认证服务获取认证:通过镜像服务获取镜像:通过仪表盘提供的用户界面与用户交互.镜像的存取受工程和用户的限制,配额受工程的限制(例如不同工程允许虚拟机实例数量不同). ...
- 快速搭建FTP服务器
快速搭建一个本地的FTP服务器 如果需要开发FTP文件上传下载功能,那么需要在本机上搭建一个本地FTP服务器,方便调试.第一步:配置IIS Web服务器1.1 控制面板中找到“程序”并打开 1.2 ...