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文档的更多相关文章

  1. Spring Boot项目使用Swagger2文档教程

    [本文版权归微信公众号"代码艺术"(ID:onblog)所有,若是转载请务必保留本段原创声明,违者必究.若是文章有不足之处,欢迎关注微信公众号私信与我进行交流!] 前言 Sprin ...

  2. PCB DotNetCore Swagger生成WebAPI文档配置方法

    在.net framework框架下可以使用WebApiTestClientWebApi生成WebAPI接口文档与方便接口测试用,而在DotnetCore却没有找到这个工具了,baidu查找一下发现有 ...

  3. swagger ui和spring boot集成生成api文档

    作者:小莫链接:https://www.zhihu.com/question/28119576/answer/134580038来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

  4. Spring Boot 基础教程系列学习文档

    Spring Boot基础教程1-Spring Tool Suite工具的安装 Spring Boot基础教程2-RESTfull API简单项目的快速搭建 Spring Boot基础教程3-配置文件 ...

  5. Spring Boot属性文件配置文档(全部)

    This sample file is meant as a guide only. Do not copy/paste the entire content into your applicatio ...

  6. Swagger生成WebAPI文档

    WebAPI2.0 项目可以使用Swagger能够轻易查看API文档,查看以下配置 1.打开程序包管理控制台输入: Install-Package Swashbuckle 2.在对应项目里的App_S ...

  7. 【原】Spring Boot 配置swagger2没有文档解决方案

    @Bean public Docket customImplementation(){ return new Docket(DocumentationType.SWAGGER_2) .select() ...

  8. 运用Swagger 添加WebAPI 文档

    1. Go to Web link https://www.nuget.org/packages/Swashbuckle/ and check which version do we want. 2. ...

  9. 使用Swagger 搭建高可读性ASP.Net WebApi文档

    一.前言 在最近一个商城项目中,使用WebApi搭建API项目.但开发过程中,前后端工程师对于沟通接口的使用,是非常耗时的.之前也有用过Swagger构建WebApi文档,但是API文档的可读性并不高 ...

随机推荐

  1. JAVA构造MAP并初始化MAP

    第一种方法:static块初始化 public class Demo{ private static final Map<String, String> myMap; static { m ...

  2. 集合之LinkedList

    一.概述 LinkedList与ArrayList一样实现List接口,只是ArrayList是List接口的大小可变数组的实现,LinkedList是List接口链表的实现.基于链表实现的方式使得L ...

  3. 【转】np.linspace()、np.logspace()、np.arange()

    转自:https://blog.csdn.net/ui_shero/article/details/78881067 1.np.linspace() 生成(start,stop)区间指定元素个数num ...

  4. 记录一个python公式罗列的方法 join()方法和map()方法的妙用

    题干: 怎样将一个列表中的元素读出,并列出计算式子 比如:[,,,] 输出:+++ = 列表中的元素个数不定 小白和大神的方法: #小白的 numlist=[,,,] sum1='' cal='+' ...

  5. ASP.NET Core 如何实现404错误跳转到主页

    假如用户在Web浏览器上敲错了URL,访问了ASP.NET Core站点下一个不存在的URL地址,那么默认情况下ASP.NET Core会返回给浏览器著名的404错误,那么有什么办法可以让ASP.NE ...

  6. easyui div 上下布局 最大化按钮 隐藏标题

    背景:easyui在做上下布局的时候,上面是数据列表,下面是数据图表.如下图 需要在上下面板右上角加上最大化按钮,以便可以全屏显示.逻辑就是当上面点击最大化时候,隐藏下面,主意:此时需要将下面的div ...

  7. [控件] Firemonkey 跨平台 Toast

    控件说明:一个简单的讯息提示功能,使用 FMX 基本控件,因此支持 Win, macOS, iOS, Android 平台. 已知问题:如果使用了 WebBrowser, MapView... 等原生 ...

  8. 生死系列--SongXingZhi

    SongXingZhi,我上中专时的同学,任劳动委员,湖北随州人.其实在上学以及毕业后,我们俩没什么交往,也没说过几句话. 印象比较深的一次是在上什么课时,老师拖堂了 ,他直接从课桌上翻过来,从后门出 ...

  9. 大数据入门第九天——MapReduce详解(五)mapJoin、GroupingComparator与更多MR实例

    一.数据倾斜分析——mapJoin 1.背景 接上一个day的Join算法,我们的解决join的方式是:在reduce端通过pid进行串接,这样的话: --order ,,P0001, ,,P0001 ...

  10. 第六周课上测试-1-ch02

    第六周课上测试-1-ch02 1. 要求: 1.参考附图代码,编写一个程序 "week0601学号.c",判断一下你的电脑是大端还是小端. 2. 提交运行结果"学号XXX ...