springmvc 与 springfox-swagger2整合
一、pom.xml引入基于maven的swagger依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.</version>
</dependency> <dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.</version>
</dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.</version>
</dependency>
二、编写SwaggerConfig配置类
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration
@EnableSwagger2
@EnableWebMvc
@ComponentScan(basePackages = {"com.foriseland.fsoa.pay.controller"})
public class SwaggerConfig {
@Bean
public Docket customDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
} private ApiInfo apiInfo() {
Contact contact = new Contact("支付组", "", "");
return new ApiInfoBuilder()
.title("支付API接口")
.description("支付API接口")
.contact(contact)
.version("1.1.0")
.build();
}
}
三、在spring mvc配置xml里面加入Swagger配置
<!-- swagger -->
<bean class="com.foriseland.fsoa.pay.swagger.SwaggerConfig"></bean>
<mvc:default-servlet-handler/>
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
四、controller层的编写例子
@Controller
@CrossOrigin
@Api(tags="账户信息控制类")
@RequestMapping("account")
public class AccountController{ @ApiOperation(value = "获取盈豆数量", notes = "获取盈豆数量", httpMethod = "POST")
@RequestMapping(value="getBeansNumber", method=RequestMethod.POST)
@ResponseBody
public void getBeansNumber(@RequestBody BeansCountDto info, HttpServletResponse response) { }
}
五、启动项目
http://127.0.0.1:8080/{projectName}/swagger-ui.html
参考:https://blog.csdn.net/lovelichao12/article/details/79387569
springmvc 与 springfox-swagger2整合的更多相关文章
- SpringMVC中使用Swagger2整合
Swagger2是什么 Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件. Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 W ...
- MP实战系列(十)之SpringMVC集成SpringFox+Swagger2
该示例基于之前的实战系列,如果公司框架是使用JDK7以上及其Spring+MyBatis+SpringMVC/Spring+MyBatis Plus+SpringMVC可直接参考该实例. 不过建议最好 ...
- 使用springfox+swagger2书写API文档(十八)
使用springfox+swagger2书写API文档 springfox是通过注解的形式自动生成API文档,利用它,可以很方便的书写restful API,swagger主要用于展示springfo ...
- SpringBoot与Swagger2整合
一.Swagger简介与优势 相信各位在公司写API文档数量应该不少,当然如果你还处在自己一个人开发前后台的年代,当我没说,如今为了前后台更好的对接,还为了以后交接方便,都有要求写API文档. Swa ...
- swagger-ui 系统配置过程(基于spring+springmvc+swagger+springfox配置 web-api 管理系统)
web工程部分框架信息:spring springmvc swagger springfox maven 参考文档:https://www.cnblogs.com/exmyth/p/7183753.h ...
- 1.springMVC+spring+Mybatis的整合思路
SSM整合的过程:就是把一些东西交给spring管理,也就是添加配置文件的一个过程.那么有哪些东西我们要交给spring管理呢?大概有以下几个: 1.数据源(可配置数据库连接池) 2.SqlSessi ...
- SSM框架整合的详细过程(含每一步的分析及代码)。实质上是SpringMVC与mybatis的整合,应为spring与SpringMVC不需要整合。
为了更好的学习 springmvc和mybatis整合开发的方法,需要将springmvc和mybatis进行整合. 整合目标:控制层采用springmvc.持久层使用mybatis实现. 1.1 需 ...
- Spring+SpringMVC+MyBatis+Maven框架整合
本文记录了Spring+SpringMVC+MyBatis+Maven框架整合的记录,主要记录以下几点 一.Maven需要引入的jar包 二.Spring与SpringMVC的配置分离 三.Sprin ...
- SpringMVC:学习笔记(10)——整合Ckeditor且实现图片上传
SpringMVC:学习笔记(10)——整合Ckeditor且实现图片上传 配置CKEDITOR 精简文件 解压之后可以看到ckeditor/lang下面有很多语言的js,如果不需要那么多种语言的,可 ...
- JavaWeb_(SpringMVC框架)测试SpringMVC&Spring&MyBatis三大整合
搭建 SpringMVC&Spring&MyBatis三大整合 传送门 1.准备 测试搭建S pringMVC&Spring&MyBatis三大整合 用例 a)准备 ...
随机推荐
- 并查集(disjoint set)的实现及应用
这里有一篇十分精彩.生动的 并查集详解 (转): "朋友的朋友就是朋友"⇒ 传递性,建立连通关系 disjoint set,并查集(一种集合),也叫不相交集,同时也是一种树型的数据 ...
- 调用另一个Activity 分类: H1_ANDROID 2013-09-22 14:11 2217人阅读 评论(0) 收藏
参考自Google官方文档Traning/Getting Started/Building a simple user interface, Startinganother activity,http ...
- C# 使用 RabbitMQ
1. RabbitMQ MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过写和检索出入列队的针对应用程序的数据(消息)来通信,而无需专用连接来链接 ...
- gradle导出依赖的jar包
gradle导出依赖的jar包 http://blog.csdn.net/yuhentian/article/details/50426896
- 如何编辑SDE数据库(转载)
转自原文 如何编辑SDE数据库(转载) 如何编辑SDE数据(转自ESRI中国社区) (2008-12-15 17:26:41) 很多刚入门的朋友对SDE数据并不太了解,接二连三的在社区里面发问,有时也 ...
- Android中的动画具体解释系列【3】——自己定义动画研究
在上一篇中我们使用到了位移动画TranslateAnimation,以下我们先来看看TranslateAnimation是怎样实现Animation中的抽象方法的: /* * Copyright (C ...
- 跟我学AngularJs:Service、Factory、Provider依赖注入使用与差别
林炳文Evankaka原创作品. 转载请注明出处http://blog.csdn.net/evankaka 本教程使用AngularJs版本号:1.5.3 AngularJ ...
- linux网络编程实现投票功能
投票系统 1.说明: 写了一个投票系统.过程是先配置好server.在写一个网上投票功能,要实现网上投票功能. 事实上功能实现还是非常easy的,麻烦一点的在于过程比較繁杂,要做的东西还是挺多的! 2 ...
- Hadoop源码分析(MapReduce概论)
大家都熟悉文件系统,在对HDFS进行分析前,我们并没有花非常多的时间去介绍HDFS的背景.毕竟大家对文件系统的还是有一定的理解的,并且也有非常好的文档.在分析Hadoop的MapReduce部分前,我 ...
- 忙里偷闲( ˇˍˇ )闲里偷学【C语言篇】——(5)有趣的指针
一.指针是C语言的灵魂 # include <stdio.h> int main(){ int *p; //p是变量名,int *表示p变量存放的是int类型变量的地址,p是一个指针变量 ...