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文档的可读性并不高 ...
随机推荐
- 随手练——HDU 5015 矩阵快速幂
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5015 看到这个限时,我就知道这题不简单~~矩阵快速幂,找递推关系 我们假设第一列为: 23 a1 a2 ...
- glusterfs分布式文件系统
第一:安装依赖包: yum install libibverbs librdmacm xfsprogs nfs-utils rpcbind libaio liblvm2app lvm2-devel ...
- [XML123] XSLT
XSLT简介 http://www.w3school.com.cn/xsl/index.asp XSLT测试 http://www.veryhuo.com/down/html/54703.html
- 手动安装sublime插件babel-sublime
(一)手动安装babel 在开发reactjs开发使用sublime时,想要代码高亮显示,需要安装babel-sublime插件,在Preferences中的Package Control菜单搜索In ...
- Docker实战(一)之使用Docker镜像
镜像是Docker三大核心概念中最为重要的,自Docker诞生之日起“镜像”就是相关社区最为热门的关键字. Docker运行容器前需要本地存在对应的镜像,如果镜像没有保存至本地,Docker会尝试先从 ...
- 【转】打包2个10g文件 测试
微博上kevin_prajna提了一个问题:“求Linux下一打包工具,需求:能把两个10G的文件打包成一个文件,时间在1分钟之内能接受!”. 暂且作答一下吧.首先问题是求解工具,那么我们忽略IO问题 ...
- vmvare安装系统提示vmci.sys 版本不正确解决方法
无法获取vmci驱动程序版本:参数不正确解决 无法获取vmci驱动程序版本:参数不正确. 驱动程序vmci.sys版本不正确. 解决办法: 1,创建好虚拟机之后,别打开电源,然后到建好的虚拟机文件夹里 ...
- Windows下修改iTunes备份路径
0.准备工作: 关闭itunes 在任务管理器中杀掉iTunes开头的服务 1,找到iTunes默认备份路径:C:\Users\xxx\AppData\Roaming\Apple Computer\M ...
- Qt中插入html样式
Qt中引入html调节样式 HTML 设置行间距字体高度和颜色 <html><head/><body><p style=\"height:16px; ...
- LaTeX源代码显示宏包listings应用备忘之新语言定义
我目前了解的LaTeX中有关源代码显示的宏包有两个,这里介绍其中的listings宏包.listings宏包中已经定义了部分计算机语言的显示样式,但还是有些语言没有定义,我们一起看一下如何定义新的 ...