spring-boot集成swagger
1、引入swagger需要的java类库
<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> <dependency>
<groupId>com.fasterxml</groupId>
<artifactId>classmate</artifactId>
<version>1.3.1</version>
</dependency>
2、引入SwaggerConfig.java类,并配置
package com.coracle.positec.xweb.swagger; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import static com.google.common.base.Predicates.or;
import static springfox.documentation.builders.PathSelectors.regex; /**
* SwaggerConfig
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
/**
* 可以定义多个组,比如本类中定义把test和demo区分开了 (访问页面就可以看到效果了)
*
*/
@Bean
public Docket testApi() {
return new Docket(DocumentationType.SWAGGER_2) .groupName("api_bsd")
.genericModelSubstitutes(DeferredResult.class)
.useDefaultResponseMessages(false)
.forCodeGeneration(false)
.pathMapping("/")
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.coracle.positec.xweb.controller")).build();
} private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("保时得项目RESTful API")
.description("保时得项目中构建RESTful API")
.termsOfServiceUrl("")
.contact("huangbaidong")
.version("1.0")
.build();
}
}
3、配置Controller接口注解
swagger类注释
@Api(value = "订单类",tags = "订单类测试接口") swagger接口注释
@ApiOperation("订单列表")
swagger参数注释
@ApiParam("订单ID")
4、配置实体注解
swagger实体类注释
@ApiModel("订单实体类")
swagger实体类中隐藏属性
@ApiModelProperty(hidden = true)
swagger实体属性备注
@ApiModelProperty("订单编号")
spring-boot集成swagger的更多相关文章
- Spring Boot 集成 Swagger,生成接口文档就这么简单!
之前的文章介绍了<推荐一款接口 API 设计神器!>,今天栈长给大家介绍下如何与优秀的 Spring Boot 框架进行集成,简直不能太简单. 你所需具备的基础 告诉你,Spring Bo ...
- Spring Boot 集成Swagger
Spring Boot 集成Swagger - 小单的博客专栏 - CSDN博客https://blog.csdn.net/catoop/article/details/50668896 Spring ...
- spring boot集成swagger,自定义注解,拦截器,xss过滤,异步调用,guava限流,定时任务案例, 发邮件
本文介绍spring boot集成swagger,自定义注解,拦截器,xss过滤,异步调用,定时任务案例 集成swagger--对于做前后端分离的项目,后端只需要提供接口访问,swagger提供了接口 ...
- 【Swagger】可能是目前最好的 Spring Boot 集成 swagger 的方案
[Swagger]可能是目前最好的Spring Boot集成 swagger 的方案  Swagger 是一个规范和完整的框架,用于生成.描述. ...
- Spring boot 集成 Swagger
添加依赖包 <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swa ...
- spring boot集成swagger文档
pom <!-- swagger --> <dependency> <groupId>io.springfox</groupId> <artifa ...
随机推荐
- Redis(十九):Redis压力测试工具benchmark
redis-benchmark使用参数介绍 Redis 自带了一个叫 redis-benchmark 的工具来模拟 N 个客户端同时发出 M 个请求. (类似于 Apache ab 程序).你可以使用 ...
- Atitit.多媒体区----web视频格式的选择总结
Atitit.多媒体区----web视频格式的选择总结 1. 因为现阶段不同的浏览器支持的视频格式是不同的 1 2. 各浏览器Html5 Video支持的影音格式: 2 3. 解决方案是什么?Flas ...
- angularJs 页面定时刷新
angularJs 页面定时刷新 页面定时刷新并在页面离开时停止自动刷新 var autoRefresh; //自动刷新 autoRefresh = $interval($scope.loadData ...
- django如何给上传的图片重命名(给上传文件重命名)
1.先在你项目中添加一个文件夹如:system 在文件夹下添加__init__.py 和storage.py文件,并在storage.py中添加如下代码: # -*- coding: UTF-8 -* ...
- jquery ajaxSubmit
<script type="text/javascript" src="jquery/jquery.js"></script></ ...
- web应用中幂等性的学习
qnmd bd:待会劳资就去买个vpn. 在平常的工作中经常听到也用到幂等,却没有及时学习总结这个知识点,现在到时候了. 幂等性最初是一个数学上的概念:在某二元运算下,幂等元素是指被自己重复运算(或对 ...
- PHP——0126最初
数据库mydb 表格info,nation 实现效果 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&quo ...
- 抹掉Scala的糖衣(14) -- Update Method
欢迎关注我的新博客地址:http://cuipengfei.me/ 在Scala中,名字叫做update的方法是有特殊作用的. 比如: 1 2 3 val scores = new scala.col ...
- grid-tooltip扩展方法
调用:$('#dg').datagrid('doCellTip', { 'max-width': '100px' }); /** * 扩展两个方法 */$.extend($.fn.datagrid.m ...
- 数据库 proc编程四
错误处理机制 当在Pro*C/C++应用程序中运行SQL语句中,Oracle会将最近执行的SQL语句的状态信息存储到状态变量SQLCODE.SQLSTATE或者SQLCA结构中. 当SQL语句执行成功 ...