swagger2的接口文档
https://www.cnblogs.com/exmyth/p/7171857.html
以前见过一个swagger2的接口文档,特别好用,好看,对接口中入参描述的很详细;适合用于项目的开发
后来自己做项目的时候,没有找到这个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>
这个版本的风格如下:

备注:
@Api: 描述类/接口的主要用途
@ApiOperation: 描述方法用途
@ApiImplicitParam: 描述方法的参数
@ApiImplicitParams: 描述方法的参数(Multi-Params)
@ApiParam:请求属性
@ApiIgnore: 忽略某类/方法/参数的文档
@ApiResponses:响应集配置
@ResponseHeader: 响应头设置
@ApiModelProperty:添加和操作模型属性的数据
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.2.2</version>
</dependency>
换了个版本,三个2的版本,

高版本UI展示变了,高版本能显示实体类中的对象属性
不是之前我看到的,还是要继续寻找更好的API接口文档展示方式。。。。
项目测试的代码

@Configuration
@EnableSwagger2 //通过@EnableSwagger2注解启用Swagger2
public class Swagger2 { @Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.demo"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Spring Boot中使用Swagger2构建RESTful APIs")
.description("更多Spring Boot相关文章请关注:https://home.cnblogs.com/u/qianjinyan/")
.termsOfServiceUrl("https://github.com/JasmineQian/")
.contact("夏天里的Jasmine")
.version("1.0")
.build();
//配置一个Docket Bean,这个Bean中,配置映射路径和要扫描的接口的位置,
// 在apiInfo中,主要配置一下Swagger2文档网站的信息,
// 例如网站的title,网站的描述,联系人的信息,使用的协议等等。
}
}
package com.example.demo.entity; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; @ApiModel
public class User { @ApiModelProperty(value = "用户id")
private int id; @ApiModelProperty(value = "用户名")
private String name; @ApiModelProperty(value = "用户地址")
private String address; 省略getters and setters void addUser(int id,String name,String address){
this.address=address;
this.id=id;
this.name=name;
}
}
package com.example.demo.controller; import com.example.demo.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*; @RestController
@Api(tags = "用户管理相关接口")
@RequestMapping("/user")
public class UserController { @PostMapping("/addUser")
@ApiOperation("添加用户的接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "username", value = "用户名", defaultValue = "李四"),
@ApiImplicitParam(name = "address", value = "用户地址", defaultValue = "深圳", required = true)}
)
public User addUser(String username, @RequestParam(required = true) String address) {
return new User();
} @GetMapping("/")
@ApiOperation("根据id查询用户的接口")
@ApiImplicitParam(name = "id", value = "用户id", defaultValue = "1", required = true)
public User getUserById(@PathVariable Integer id) {
User user = new User();
user.setId(id);
return user;
} @PutMapping("/{id}")
@ApiOperation("根据id更新用户的接口")
public User updateUserById(@RequestBody User user) {
return user;
}
}
swagger2的接口文档的更多相关文章
- Springboot集成swagger2生成接口文档
[转载请注明]: 原文出处:https://www.cnblogs.com/jstarseven/p/11509884.html 作者:jstarseven 码字挺辛苦的..... 一 ...
- Springboot+swagger2的接口文档开发
一.创建一个SpringBoot项目 1. 2. 3. 4. 把web里的web选中,SQL里选择自己需要的,点击next 二.创建各项所需的controller,configure等 1. 项目布局 ...
- SpringFox swagger2 and SpringFox swagger2 UI 接口文档生成与查看
依赖: <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <dependency ...
- SpringBoot 使用Swagger2打造在线接口文档(附汉化教程)
原文地址: https://www.jianshu.com/p/7e543f0f0bd8 SpringBoot + Swagger2 UI界面-汉化教程 1.默认的英文界面UI 想必很多小伙伴都曾经使 ...
- 接口开发-集成接口文档(swagger)
在正式进入主题之前,先说说实际工作中遇到的问题.不算是传统的原生APP开发,还是眼下的H5混合开发,只要是需要前后端通过接口配合的,往往都存在几个普遍的问题 (1)接口文档谁来写,尤其是跨部门,并且, ...
- SpringBoot整合Swagger2,再也不用维护接口文档了!
前后端分离后,维护接口文档基本上是必不可少的工作.一个理想的状态是设计好后,接口文档发给前端和后端,大伙按照既定的规则各自开发,开发好了对接上了就可以上线了.当然这是一种非常理想的状态,实际开发中却很 ...
- Spring Boot(九)Swagger2自动生成接口文档和Mock模拟数据
一.简介 在当下这个前后端分离的技术趋势下,前端工程师过度依赖后端工程师的接口和数据,给开发带来了两大问题: 问题一.后端接口查看难:要怎么调用?参数怎么传递?有几个参数?参数都代表什么含义? 问题二 ...
- springboot项目利用Swagger2生成在线接口文档
Swagger简介. Swagger2是一款restful接口文档在线生成和在线调试工具.很多项目团队利用Swagger自动生成接口文档,保证接口文档和代码同步更新.在线调试.简单地说,你可以利用这个 ...
- SpringBoot+rest接口+swagger2生成API文档+validator+mybatis+aop+国际化
代码地址:JillWen_SpringBootDemo mybatis 1. 添加依赖: <dependency> <groupId>org.mybatis.spring.bo ...
随机推荐
- 软件毕业设计文档流程与UML图之间的关系
每个模型都是用一种或者多种UML图来描述的,映射关系如下: 1.用例模型:使用用例图.顺序图.通信图.活动图和状态图来描述. 2.分析模型:使用类图和对象图(包括子系统和包).顺序图(时序图).通信图 ...
- ORACLE导入梗
1.Oracle版数据库的安装及初始化 1.1安装oracle数据库(10g或11g) 1.2以用户system账号登陆oralcle数据库的sqlplus,执行以下语句 1.3创建表空间语句: cr ...
- JavaScript基础知识(字符串的方法)
字符串的方法 1.字符串: 在js中被单引号或双引号包起来的内容都是字符串: var t = "true"; console.log(typeof t);// "stri ...
- [No0000C6]Visual Studio 2017 函数头显示引用个数
Visual Studio 2017 函数头显示引用个数
- C#4.0 HTTP协议无法使用TLS1.2的问题
在发送HTTP请求前加入下行代码 ServicePointManager.SecurityProtocol = (SecurityProtocolType) | (SecurityProtocolTy ...
- 解决IE浏览器兼容问题的一行代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 4、 LwIP协议栈规范翻译——流程模型
4.流程模型 协议实现的流程模型描述了系统被划分为不同的流程的方式.用于实现通信协议的一个流程模型是让每个协议作为一个独立的进程运行.有了这个模型,严格的协议分层被强制执行,并且协议之间的通信点必须严 ...
- ivew定制主题 less ^3.0 时报错 .bezierEasingMixin(); Inline JavaScript is not enabled. Is it set in your options?
按照 ivew 提供的方法定制主题,创建一个 less 文件,在其中覆盖变量,再在 main.js 中引入.戳这里 出现报错: 问题貌似是在于 less 版本...两种解决方法: 1.打开项目pack ...
- 三、latex源文件的基本结构
在latex中如何使用中文 首先在选项->设置->构建中默认编译器是不是用的是xelatex 编辑器的默认字体编码是不是UTF-8 在导言区引入ctex宏包
- eclispe集成Scalas环境后,导入外部Spark包报错:object apache is not a member of package org
在Eclipse中集成scala环境后,发现导入的Spark包报错,提示是:object apache is not a member of package org,网上说了一大推,其实问题很简单: ...