使用Swagger生成简单接口文档
使用swagger通过简单的配置可以生成简单的接口文档;
依赖包:
// Swagger2
compile 'io.springfox:springfox-swagger2:2.8.0'
compile 'io.springfox:springfox-swagger-ui:2.8.0'
启动类添加配置:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
@EnableAutoConfiguration
public class ShowCaseApplication { public static void main(String[] args) {
SpringApplication.run(ShowCaseApplication.class, args);
}
}
配置类:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
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.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration
@ComponentScan(basePackages = { //"com.a.controller", //
})
@EnableSwagger2
public class AutoConfiguration { @Bean
public Docket docketCommon() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("test").select()
.apis(RequestHandlerSelectors.basePackage("com.a.controller"))
.paths(PathSelectors.any())
.build()
.apiInfo(new ApiInfoBuilder().
title("test Restful API").
description("接口API").
contact(new Contact("", "", "")).
version("1.0").
build());
}
}
接口注释:在controller里的接口上面添加标识
@ApiOperation(nickname = "getList", value = "获取列表。")
@Override
public List<String> getList(
@RequestBody @ApiParam(name = "请求对象", value = "传入json格式", required = true) TestRequest request) {
return null
}
使用Swagger生成简单接口文档的更多相关文章
- spring boot使用swagger生成api接口文档
前言 在之前的文章中,使用mybatis-plus生成了对应的包,在此基础上,我们针对项目的api接口,添加swagger配置和注解,生成swagger接口文档 具体可以查看本站spring boot ...
- .NET Core WEB API使用Swagger生成在线接口文档
1项目引用Swashbuckle.AspNetCore程序集和Microsoft.Extensions.PlatformAbstractions程序集 右击项目打开"管理NuGet程序包.. ...
- swagger 生成的接口文档,隐藏接口的某个参数
[问题描述] controller 中的处理请求的方法,有时候会添加一些额外的参数.比如下面代码中 UserVo: @PostMapping(value = "/add-office-par ...
- .netcore Swagger 生成 api接口文档
1, 引用第三方包, Swashbuckle.AspNetCore Swashbuckle.AspNetCore.Swagger Swashbuckle.AspNetCore.SwaggerUI 最简 ...
- Swagger+Spring mvc生成Restful接口文档
简介 Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目标是使客户端和文件系统作为服务器以同样的速度来更新.文件的方法,参数和模型紧密集 ...
- Spring Boot 集成 Swagger 生成 RESTful API 文档
原文链接: Spring Boot 集成 Swagger 生成 RESTful API 文档 简介 Swagger 官网是这么描述它的:The Best APIs are Built with Swa ...
- Spring MVC学习总结(9)——Spring MVC整合swagger自动生成api接口文档
Swagger 号称:世界最流行的API框架,官网:http://swagger.io/,Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总 ...
- Swagger: 一个restful接口文档在线生成+功能测试软件
一.什么是 Swagger? Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件.Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 ...
- springboot项目利用Swagger2生成在线接口文档
Swagger简介. Swagger2是一款restful接口文档在线生成和在线调试工具.很多项目团队利用Swagger自动生成接口文档,保证接口文档和代码同步更新.在线调试.简单地说,你可以利用这个 ...
随机推荐
- 【bzoj2144】跳跳棋
2144: 跳跳棋 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 492 Solved: 244[Submit][Status][Discuss] ...
- SSH连接Linux
转载自百度经验 https://jingyan.baidu.com/article/bea41d439d16d7b4c51be619.html 连接Linux的工具有Putty.SSH Secure ...
- sql server 错误总结
1>无法访问sql server2000数据库 1.1>安装sql server2000 sp1的补丁包. 1.2>sql server 数据库开启了允许远程访问. 1.3>s ...
- linux的deamon后台运行
有的时候需要将程序一直跑在后台,比如一些服务类代码,或者一些监控类代码.使用deamon是正确的一种思路. 以前我们在看<unix环境高级编程>的时候,有专门的整章详细介绍如何编写一个后台 ...
- 基于PCL的屏幕选点、框选点云、单点选取
1. 单点选取 #include <pcl/io/pcd_io.h> #include <pcl/point_cloud.h> #include <pcl/point_t ...
- 17.SQL 约束
约束用于限制加入表的数据的类型. 可以在创建表时规定约束(通过 CREATE TABLE 语句),或者在表创建之后也可以(通过 ALTER TABLE 语句). 我们将主要探讨以下几种约束: NOT ...
- PHP中 null ,false , 区别
先来测试一下吧: if(0 ==''){ echo '<br/>在PHP中0 ==\'\'' ; } if(0 !==''){ echo '<br/>在PHP中0 !==\'\ ...
- combogrid change check multiple
this.SetDict = function (obj, dicType, multiple, Ischeckbox, callback, change) { obj.combogrid({ pan ...
- JavaScript补充:BOM(浏览器对象模型)
一些公共对象.详细参考手册. 一.Window 对象 Window 对象表示浏览器中打开的窗口. 如果文档包含框架(<frame> 或 <iframe> 标签),浏览器会为 H ...
- rsync 备份服务搭建(完成)
rsync服务守护进程 服务器端配置过程: 1. 检查rsync是否安装: rpm -qa rsync 2.添加rsync服务的用户,管理本地目录 useradd-s /sbin/nologin -M ...