spring-boot+swagger实现WebApi文档
1、引用依赖包
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.5.0</version>
</dependency
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.5.0</version>
</dependency>
2、新建 SwaggerConfig 类
package cn.com.xxx.config; import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration
@EnableSwagger2
public class SwaggerConfig { public Docket swaggerSpringMvcPlugin(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.build();
}
}
3、配置接口类
package cn.com.xxx.controller; import cn.com.xxx.dao.AccountDao;
import cn.com.xxx.po.T_Account;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; @Api(value = "")
@RestController
@RequestMapping(value = "/api/test")
public class ApiTestController {
@Autowired
private AccountDao accountDao; @ApiOperation(nickname = "获取人员信息",value = "账号")
@RequestMapping(value = "/getAccountByUserName/{userName}",method = RequestMethod.GET)
public T_Account getAccountByUserName(@PathVariable("userName") String userName){ return accountDao.findUserInfoByUserName(userName);
}
}
4、配置spring boot启动类
package cn.com.xxx; import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList;
import java.util.List; /**
* Hello world!
*
*/
@MapperScan(basePackages = {"cn.com.xxx.dao"})
@SpringBootApplication(scanBasePackages = {"cn.com.xxx"})
public class App
{
private static final Logger logger = LoggerFactory.getLogger(App.class);
public static void main( String[] args )
{
logger.info("开始启动");
SpringApplication.run(App.class,args);
logger.info("启动结束");
} }
5、启动spring boot并访问:http://localhost:端口/swagger-ui.html

6、输入测试数据并获取结果


至此集成spring+swagger集成结束。
spring-boot+swagger实现WebApi文档的更多相关文章
- Spring Boot项目使用Swagger2文档教程
[本文版权归微信公众号"代码艺术"(ID:onblog)所有,若是转载请务必保留本段原创声明,违者必究.若是文章有不足之处,欢迎关注微信公众号私信与我进行交流!] 前言 Sprin ...
- PCB DotNetCore Swagger生成WebAPI文档配置方法
在.net framework框架下可以使用WebApiTestClientWebApi生成WebAPI接口文档与方便接口测试用,而在DotnetCore却没有找到这个工具了,baidu查找一下发现有 ...
- swagger ui和spring boot集成生成api文档
作者:小莫链接:https://www.zhihu.com/question/28119576/answer/134580038来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...
- Spring Boot 基础教程系列学习文档
Spring Boot基础教程1-Spring Tool Suite工具的安装 Spring Boot基础教程2-RESTfull API简单项目的快速搭建 Spring Boot基础教程3-配置文件 ...
- Spring Boot属性文件配置文档(全部)
This sample file is meant as a guide only. Do not copy/paste the entire content into your applicatio ...
- Swagger生成WebAPI文档
WebAPI2.0 项目可以使用Swagger能够轻易查看API文档,查看以下配置 1.打开程序包管理控制台输入: Install-Package Swashbuckle 2.在对应项目里的App_S ...
- 【原】Spring Boot 配置swagger2没有文档解决方案
@Bean public Docket customImplementation(){ return new Docket(DocumentationType.SWAGGER_2) .select() ...
- 运用Swagger 添加WebAPI 文档
1. Go to Web link https://www.nuget.org/packages/Swashbuckle/ and check which version do we want. 2. ...
- 使用Swagger 搭建高可读性ASP.Net WebApi文档
一.前言 在最近一个商城项目中,使用WebApi搭建API项目.但开发过程中,前后端工程师对于沟通接口的使用,是非常耗时的.之前也有用过Swagger构建WebApi文档,但是API文档的可读性并不高 ...
随机推荐
- 解析Array.prototype.slice.call(arguments)
在es5标准中,我们经常需要把arguments对象转换成真正的数组 // 你可以这样写 var arr = Array.prototype.slice.call(arguments) // 你还可以 ...
- node-webkit,nwjs 打包启动启动很慢解决办法
要开发一个桌面程序,可选择的有nwjs和electron,但是electron不支持xp,客户还是有一部分系统是用xp的,只能用nwjs. 由于程序需要安装很多npm的模块,node_module文件 ...
- PAT乙级1020
1020 月饼 (25 分) 月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼.现给定所有种类月饼的库存量.总售价.以及市场的最大需求量,请你计算可以获得的最大收益是多少. ...
- POJ 1321 棋盘问题(非常经典的dfs,入门题)
棋盘问题 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 66277 Accepted: 31639 Descriptio ...
- Jquery中的height(),innerHeight(),outerHeight()的区别
前言 最近练习做弹窗,遇到height(),innerHeight(),outerHeight()的区别. 根据下面的盒模型来了解三者的区别. height():element的height; inn ...
- ubuntu18.04(bionic) 配置阿里数据源
先备份源数据原文件 cp sources.list sources.list.bak 编辑 sources.list,输入内容如下: deb http://mirrors.aliyun.com/ubu ...
- MySQL添加、删除索引
1.索引类型 UNIQUE(唯一索引):不可以出现相同的值,可以有NULL值: INDEX(普通索引):允许出现相同的索引内容: PROMARY KEY(主键索引):不允许出现相同的值: fullte ...
- Liunx信息显示与文件搜索
. uname 显示系统相关信息,如内核版本号,硬件架构 -a # 显示系统所有相关信息 -m # 显示计算机硬件架构 -n # 显示主机名称 -r # 显示内核发行版本号 -s # 显示内核名称 - ...
- 基于FPGA的DDS设计(一)
最近在学习基于FPGA的DDS设计,借此机会把学习过程记录下来,当作自己的学习笔记也希望能够帮助到学习DDS的小伙伴. DDS(Direct Digital Synthesizer)直接数字合成器,这 ...
- PostgreSQL参数学习:deadlock_timeout
磨砺技术珠矶,践行数据之道,追求卓越价值回到上一级页面:PostgreSQL基础知识与基本操作索引页 回到顶级页面:PostgreSQL索引页[作者 高健@博客园 luckyjackgao@g ...