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:/ ...
随机推荐
- js 三级联动
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- JS OOP -04 JS中的公有成员,私有成员和静态成员
JS中的公有成员,私有成员和静态成员 a.实现类的公有成员 b.实现类的私有成员 c.实现类的静态成员 a.实现类的公有成员 之前定义的任何类型成员都属于公有成员的范畴,该类的任何实例都对外公开这些属 ...
- requests Use body.encode('utf-8') if you want to send it encoded in UTF-8
基本环境 使用 requests 模块发送 post 请求,请求体包含中文报错 系统环境:centos7.3 python版本:python3.6.8 请求代码: // 得到中文 param_json ...
- pytorch自定义网络层以及损失函数
转自:https://blog.csdn.net/dss_dssssd/article/details/82977170 https://blog.csdn.net/dss_dssssd/articl ...
- Mysql连接数设置
在使用MySQL数据库的时候,经常会遇到这么一个问题,就是“Can not connect to MySQL server. Too many connections”-mysql 1040错误,这是 ...
- Pandas进阶之提升运行效率
前言 如果你现在正在学习数据分析,或者正在从事数据分析行业,肯定会处理一些大数据集.pandas就是这些大数据集的一个很好的处理工具.那么pandas到底是什么呢?官方文档上说: " 快速, ...
- springboot启动流程(六)ioc容器刷新前prepareContext
所有文章 https://www.cnblogs.com/lay2017/p/11478237.html prepareContext方法核心逻辑 上一篇文章中,我们通过createApplicati ...
- 编译 recastnavigation
1. https://github.com/memononen/recastnavigation 下载zip并解压 2. 打开https://www.libsdl.org/download-2.0 ...
- Image Processing and Analysis_8_Edge Detection:Edge Detection Revisited ——2004
此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...
- pytorch训练模型的一些坑
1. 图像读取 opencv的python和c++读取的图像结果不一致,是因为python和c++采用的opencv版本不一样,从而使用的解码库不同,导致读取的结果不同. 详细内容参考:https:/ ...