Swagger-ui接口文档
参考地址
说明
注解
实践
@Api(value="用户controller",tags={"用户操作接口"})
@RestController
public class UserController {
}
@Api(value="UserController",tags={"用户接口"})
@RestController
public class UserController {
@ApiOperation(value="获取用户信息",tags={"获取用户信息"},notes="注意")
@GetMapping("/getUserInfo")
public User getUserInfo(@ApiParam(name="id",value="用户id",required=true) Long id,@ApiParam(name="username",value="用户名") String username) {
User user = userService.getUserInfo();
return user;
}
}
@ApiModel(value="user",description="用户对象")
@Data
public class User implements Serializable{
private static final long serialVersionUID = 1L;
@ApiModelProperty(value="用户名",name="username",example="xingguo")
private String username;
@ApiModelProperty(value="状态",name="state",required=true)
private Integer state;
private String password;
private String nickName;
private Integer isDeleted; @ApiModelProperty(value="ids",hidden=true)
private String[] ids;
private List<String> idList;
}
@ApiOperation("修改用户信息")
@PostMapping("/updateUserInfo")
public int updateUserInfo(@RequestBody @ApiParam(name="用户对象",value="json格式",required=true) User user){
int num = userService.updateUserInfo(user);
return num;
}
@ApiOperation("查询测试")
@GetMapping("select")
//@ApiImplicitParam(name="name",value="用户名",dataType="String", paramType = "query")
@ApiImplicitParams({
@ApiImplicitParam(name="name",value="用户名",dataType="string", paramType = "query",example="xingguo"),
@ApiImplicitParam(name="id",value="用户id",dataType="long", paramType = "query")})
public void select(){
}
pom依赖
<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>
<!-- 下面这个界面更好看,更好用-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.5</version>
</dependency>
具体配置
import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import java.util.ArrayList;
import java.util.List; /**
* swagger-api 配置
*
* @author wzm
* @version 1.0.0
* @date 2019/6/15
**/
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class Swagger2 { /**
* http://localhost:8085/fabric-net/swagger-ui.html
* http://localhost:8085/fabric-net/doc.html
*/ private static final String SWAGGER_SCAN_BUSINESS_PACKAGE = "com.thyc.fabric.controller.business";
private static final String BUSINESS_VERSION = "1.0.0"; private static final String SWAGGER_SCAN_FABRIC_PACKAGE = "com.thyc.fabric.controller.fabric";
private static final String FABRIC_VERSION = "1.0.0"; @Bean
public Docket createBusinessApi() {
List<Parameter> pars = new ArrayList<>();
ParameterBuilder ticketPar1 = new ParameterBuilder();
ticketPar1.name("Authorization").description("登录令牌")
.modelRef(new ModelRef("string")).parameterType("header")
.required(false).build();
pars.add(ticketPar1.build());
return new Docket(DocumentationType.SWAGGER_2)
.globalOperationParameters(pars)
//分组名不支持中文
.groupName("business")
.apiInfo(apiBusinessInfo())
.pathMapping("/")
.select()
// 对所有api进行监控
.apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BUSINESS_PACKAGE))
// 错误路径不监控
.paths(Predicates.not(PathSelectors.regex("/error.*")))
// 对根下所有路径进行监控
.paths(PathSelectors.regex("/.*"))
.build();
} private ApiInfo apiBusinessInfo() {
Contact contact = new Contact("thyc","thyc.com","thyc@email");
return new ApiInfoBuilder()
//设置文档的标题
.title("Business")
//设置文档的描述->1.Overview
.description("业务模块数据管理")
//设置文档的版本信息-> 1.1 Version information
.termsOfServiceUrl("http://localhost:8085/fabric-net")
.contact(contact)
.version(BUSINESS_VERSION)
.build();
} //------------------------------------------------------------------------------------------------------------------ @Bean
public Docket createFabricApi() {
List<Parameter> pars = new ArrayList<Parameter>();
ParameterBuilder ticketPar1 = new ParameterBuilder();
ticketPar1.name("Authorization").description("登录令牌")
.modelRef(new ModelRef("string")).parameterType("header")
.required(false).build();
pars.add(ticketPar1.build());
return new Docket(DocumentationType.SWAGGER_2)
.globalOperationParameters(pars)
//分组名不支持中文
.groupName("fabric")
.apiInfo(apiFabricInfo())
.pathMapping("/")
.select()
// 对所有api进行监控
.apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_FABRIC_PACKAGE))
// 错误路径不监控
.paths(Predicates.not(PathSelectors.regex("/error.*")))
// 对根下所有路径进行监控
.paths(PathSelectors.regex("/.*"))
.build();
} private ApiInfo apiFabricInfo() {
Contact contact = new Contact("thyc","thyc.com","thyc@email");
return new ApiInfoBuilder()
//设置文档的标题
.title("Fabric-Network")
//设置文档的描述->1.Overview
.description("超级账本网络信息管理")
//设置文档的版本信息-> 1.1 Version information
.termsOfServiceUrl("http://localhost:8085/fabric-net")
.contact(contact)
.version(FABRIC_VERSION)
.build();
} }
Swagger-ui接口文档的更多相关文章
- TP框架整合Swagger UI接口文档
1.下载swagger ui:http://swagger.io/swagger-ui/: 2.在应用目录里新建一个目录xxx:如图 3.解压后把dist目录的所有文件拷贝到新建的目录里面: 4.在新 ...
- asp.net core 使用 swagger 生成接口文档
参考地址:http://www.cnblogs.com/daxnet/p/6181366.html http://www.jianshu.com/p/fa5a9b76f3ed 微软参考文档:https ...
- .net core 使用 swagger 生成接口文档
微软参考文档:https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger?tabs= ...
- webapi 利用webapiHelp和swagger生成接口文档
webapi 利用webapiHelp和swagger生成接口文档.均依赖xml(需允许项目生成注释xml) webapiHelp:微软技术自带,仅含有模块.方法.请求-相应参数的注释. swagge ...
- Spring Boot 集成 Swagger 构建接口文档
在应用开发过程中经常需要对其他应用或者客户端提供 RESTful API 接口,尤其是在版本快速迭代的开发过程中,修改接口的同时还需要同步修改对应的接口文档,这使我们总是做着重复的工作,并且如果忘记修 ...
- .net WebApi使用swagger 美化接口文档
本文将一步步演示如何用swagger美化WebApi接口文档,为接口文档添加接口名称说明,为请求参数和返回数据结构字段含义添加注释说明 一.为WebApi项目安装Swagger 首先我们新建一个Web ...
- spring-boot-route(五)整合Swagger生成接口文档
目前,大多数公司都采用了前后端分离的开发模式,为了解决前后端人员的沟通问题,后端人员在开发接口的时候会选择使用swagger2来生成对应的接口文档,swagger2提供了强大的页面调试功能,这样可以有 ...
- 用Swagger生成接口文档
Swagger简介 在系统设计的时候,各个应用之间往往是通过接口进行交互的.因此接口的定义在整个团队中就变得尤为重要.我们可以把接口的规范用接口描述语言进行描述,然后Swagger可以根据我们定义的接 ...
- asp.net core使用Swashbuckle.AspNetCore(swagger)生成接口文档
asp.net core中使用Swashbuckle.AspNetCore(swagger)生成接口文档 Swashbuckle.AspNetCore:swagger的asp.net core实现 项 ...
- 基于swagger进行接口文档的编写
0. 前言 近期忙于和各个银行的代收接口联调,根据遇到的问题,对之前编写的接口进行了修改,需求收集和设计接口时想到了方方面面,生产环境下还是会遇到意想不到的问题,好在基本的执行逻辑已确定,因此只是对接 ...
随机推荐
- PAT - A1073
1073 Scientific Notation (20point(s)) 小数点移动的边界条件 小数点左移 超过数据左边界 小数点右移 未超过数据右边界 超过数据右边界 +0.1E+2 --> ...
- mysql 数据备份。pymysql模块
阅读目录 一 IDE工具介绍 二 MySQL数据备份 三 pymysql模块 一 IDE工具介绍 生产环境还是推荐使用mysql命令行,但为了方便我们测试,可以使用IDE工具 下载链接:https:/ ...
- Oracle 12c 如何在 PDB 中添加 SCOTT 模式(数据泵方式)
Oracle 12c 建库后,没有 scott 模式,本篇使用数据泵方式,在12c版本之前数据库中 expdp 导出 scott 模式,并连接 12c 的 pdb 进行 impdp 导入. 目录 1. ...
- gtid环境下mysqldump对于set-gtid-purged的取值
gtid环境备份的时候,还在为set-gtid-purged=0|1的选择而烦恼吗,一起来分析一下. [mysql@lxd-vm1@/home/mysql]$ mysqldump --help | g ...
- 洛谷p1980 计数问题
题目描述 试计算在区间 111 到 nn n的所有整数中,数字x(0≤x≤9) x(0 ≤ x ≤ 9)x(0≤x≤9)共出现了多少次?例如,在 111到11 11 11中,即在 1,2,3,4,5, ...
- 诡异的Integer
先看下面的这个代码,为什么同样的都是赋值,却得不到同样的结果,也没有超出int的范围啊?这是为什么? package ppt_test; public class StrangeIntegerBeha ...
- tcolorbox 宏包简明教程
嗯,我消失好几天了.那么,我都在做什么呢?没错,就是写这篇文章了.这篇文章写起来着实有些费神了.于是,如果你觉得这篇文章对你有帮助,不妨扫描文末的二维码,适量赞助一下哦~! tcolorbox 宏包是 ...
- LaTeX技巧012:LaTeX 插图加载宏包
LaTeX 插图加载宏包.支持 LaTeX - DVIPDFMx; pdfLaTeX; XeLaTeX 三种编译方式,支持 eps/pdf/jpg/png 等图片格式. % Put this snip ...
- AI: Uninformed search
What is a search problem: A solution to a search problem is a sequence of actions (a path) from s0 t ...
- 我的python笔记06
面向对象学习 本节内容: 面向对象编程介绍 为什么要用面向对象进行开发? 面向对象的特性:封装.继承.多态 类.方法. 引子 你现在是一家游戏公司的开发人员,现在需要你开发一款叫做< ...