springBoot 集成swagger2.9.2
加依赖
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
springBoot的application.java的同级目录下新建SwaggerConfiguration类
package com.example.demo; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(getApiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.demo.controller")) //过滤的接口
.paths(PathSelectors.any())
.build();
} private ApiInfo getApiInfo() {
// 定义联系人信息
Contact contact = new Contact("name","https://baidu.com", "test@test.com");
return new ApiInfoBuilder()
.title("标题")
.description("描述")
.version("版本")
.license("Apache 2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
.contact(contact)
.build();
}
}
controller类:
@RestController
@Api(value = "/user",description = "这个是用户信息 ",tags = "用户信息")
@RequestMapping("/user")
public class UserContrller { @ApiOperation(value="获取用户列表", notes="")
@GetMapping("")
public List<User> getUserList() {
return null;
} @ApiOperation(value="创建用户", notes="根据User对象创建用户")
@PostMapping("")
public String postUser(@RequestBody User user) {
return "success";
}
}
浏览器输入 http://localhost:8080/swagger-ui.html 访问

这样就完成了, 接下来就是去搜Swagger的常用注解怎么使用就ok了。 附上链接: https://github.com/swagger-api/swagger-core/wiki/annotations
——————————————————————————————————————
以下是我遇到的部分问题
@ApiImplicitParam 注解: 如果参数是实体类并且实体类中被@ApiModel和@ApiModelProperty注解修饰过, @ApiImplicitParam注解就不要加了。
如果,没有实体类没有被@ApiModel和@ApiModelProperty注解修饰过, @ApiImplicitParam可加可不加, 另外在实体类参数之前加上@RequestBody 和不加@RequestBody,swagger的文档参数显示是不一样的
比如不加@RequestBody注解的代码:
@ApiOperation(value="创建用户", notes="根据User对象创建用户")
@PostMapping("")
public String postUser(User user) {
users.put(user.getId(), user);
return "success";
}
User实体:
package com.example.demo.model; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; @ApiModel(value = "用户信息", description = "这个用户信息只用于测试")
@Data
public class User { @ApiModelProperty("id")
private Long id; @ApiModelProperty(value="姓名",required=true)
private String name; @ApiModelProperty("年龄")
private Integer age;
}
swagger显示的参数是这样的

加了@RequestBody
@ApiOperation(value="创建用户", notes="根据User对象创建用户")
@PostMapping("")
public String postUser(@RequestBody User user) {
users.put(user.getId(), user);
return "success";
}
加了@RequestBody的swagger:


springBoot 集成swagger2.9.2的更多相关文章
- SpringBoot集成Swagger2实现Restful(类型转换错误解决办法)
		
1.pom.xml增加依赖包 <dependency> <groupId>io.springfox</groupId> <artifactId>spri ...
 - springboot集成swagger2构建RESTful API文档
		
在开发过程中,有时候我们需要不停的测试接口,自测,或者交由测试测试接口,我们需要构建一个文档,都是单独写,太麻烦了,现在使用springboot集成swagger2来构建RESTful API文档,可 ...
 - SpringBoot集成Swagger2在线文档
		
目录 SpringBoot集成Swagger2在线文档 前言 集成SpringBoot 登录接口文档示例 代码 效果 注解说明 总结 SpringBoot集成Swagger2在线文档 前言 不得不说, ...
 - springboot 集成swagger2.x 后静态资源报404
		
package com.bgs360.configuration; import org.springframework.context.EnvironmentAware; import org.sp ...
 - SpringBoot集成Swagger2并配置多个包路径扫描
		
1. 简介 随着现在主流的前后端分离模式开发越来越成熟,接口文档的编写和规范是一件非常重要的事.简单的项目来说,对应的controller在一个包路径下,因此在Swagger配置参数时只需要配置一 ...
 - springboot集成swagger2报Illegal DefaultValue null for parameter type integer
		
springboot集成swagger2,实体类中有int类型,会报" Illegal DefaultValue null for parameter type integer"的 ...
 - SpringBoot集成Swagger2 以及汉化 快速教程
		
(一) Swagger介绍 Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件 (二)为什么使用Swagger 在现在的开发过程中还有很大一部分公司都是以口口相传的方式来进行 ...
 - Springboot集成swagger2生成接口文档
		
[转载请注明]: 原文出处:https://www.cnblogs.com/jstarseven/p/11509884.html 作者:jstarseven 码字挺辛苦的..... 一 ...
 - springboot 集成swagger2
		
使用Swagger 可以动态生成Api接口文档,在项目开发过程中可以帮助前端开发同事减少和后端同事的沟通成本,而是直接参照生成的API接口文档进行开发,提高了开发效率.这里以springboot(版本 ...
 - [转] spring-boot集成swagger2
		
经测,spring-boot版本使用1.5.2+时需使用springfox-swagger2版本2.5+(spring-boot 1.2 + springfox-swagger2 2.2 在未扫描ja ...
 
随机推荐
- 微信小程序采坑之上拉触底加载更多和下拉刷新
			
小程序中加载更多数据一般都是触底刷新 有自带的函数: onReachBottom: function (){} 但是在使用时触发完全没有反应,后来尝试给外层加了一个高度,解决问题 仔细想想也是,没有设 ...
 - Jmeter 的 vars 和 props 用法
			
meter 的 JSR223 控件是 代替 BeanShell 的新一代脚本控件,支持多种脚本语言,尤其是其中的 Groovy,更是重点推荐使用的脚本语言,本文研究其中的 vars 和 props 两 ...
 - Linux操作学习笔记1
			
Linux只有一个根目录/,所有的文件和设备都当成是文件进行管理: pwd 打印当前工作目录 (print working directory) whoami ls 列出当前目录面的文件 ls -l ...
 - spark-2.2.0-bin-hadoop2.6和spark-1.6.1-bin-hadoop2.6发行包自带案例全面详解(java、python、r和scala)之Basic包下的JavaPageRank.java(图文详解)
			
不多说,直接上干货! spark-1.6.1-bin-hadoop2.6里Basic包下的JavaPageRank.java /* * Licensed to the Apache Software ...
 - .NET资源站点汇总~
			
名称:快速入门地址:http://chs.gotdotnet.com/quickstart/描述:本站点是微软.NET技术的快速入门网站,我们不必再安装.NET Framework中的快速入门示例程序 ...
 - Ionic开发-常用命令
			
$ionic start myApp [tabs | sidemenu | blank] $ionic platform add android $ionic build android $ion ...
 - webpack.config.js====插件purifycss-webpack,提炼css文件
			
1. 安装:打包编译时,可以删除一些html中没有使用的选择器,如果html页面中没有class=a class="b"的元素,.a{}.b{}样式不会加载 cnpm instal ...
 - 关于使用memcached提高并发的文章,很有用
			
http://blog.csdn.net/ywh147/article/details/9385137 http://phl.iteye.com/category/292555 memcached 解 ...
 - 获取url的参数值
			
var url=location.search; //获取url中从?开始的所有字符 var theRequest=new Object();//定义一个对象来存放url中的参数 if( url.i ...
 - 零基础逆向工程16_C语言10_宏定义_头文件_内存分配_文件读写
			
#define 无参数的宏定义的一般形式为:#define 标识符 字符序列 如:#define TRUE 1 注意事项: 1.之作字符序列的替换工作,不作任何语法的检查 2.如果宏定义不当,错误要到 ...