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)准备 ...
随机推荐
- webuploader 小demo
页面写法 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- localStorage兼容方案
localStorage是H5的存储方案,各大浏览器支持都相当不错,唯一悲催的就是IE,这个浏览器界的另类总是显得格格不入. IE “Internet选项”->“安全”中有一个“启动保护模式”的 ...
- [AngularFire2] Signup and logout
import {AuthProviders, FirebaseAuthState, FirebaseAuth, AuthMethods} from "angularfire2";i ...
- php 图片加水印文字水印
/*给图片加文字水印的方法*/ $dst_path = 'http://f4.topitme.com/4/15/11/1166351597fe111154l.jpg';//保证路径正确 $dst = ...
- WP8.1:onedrive操作
小梦今天给大家分享一下windows phone 8.1开发 onedrive中的一些操作: Windows phone 8.1 中 onedrive 登录 Windows phone 8.1 中 o ...
- Linux下使用Python的Tkinter库出现的No module named _tkinter问题
这是由于python的版本没有包含tkinter的模块,只需要把tk的package安装就可以了. 一般在linux才出现,windows版本一般已经包含了tkinter模块.
- Android自定义组件系列【4】——自定义ViewGroup实现双侧滑动
在上一篇文章<Android自定义组件系列[3]--自定义ViewGroup实现侧滑>中实现了仿Facebook和人人网的侧滑效果,这一篇我们将接着上一篇来实现双面滑动的效果. 1.布局示 ...
- jquery-2 jQuery原理和核心方法(多看学习视频)
jquery-2 jQuery原理和核心方法(多看学习视频) 一.总结 一句话总结:jQuery就是普通的js对象,只不过方法比较多而已,属性就length一个. 1.jquery的链式操作的底层原 ...
- Linux删除非空目录
Linux下如何删除非空目录 这个问题很basic,不过还是困扰了我一段时间.(这里主要讨论的是命令行模式下)我本来觉得应该使用命令 rmdir但是发现它无法删除非空的目录.后来发现了原来应该使用 ...
- [_UICascadingTextStorage attributesAtIndex:effectiveRange:]: Range or index out of bounds
之前写过一篇<如何更好地限制一个UITextField的输入长度>,在文章最后得到的结论是可以直接使用 UIKIT_EXTERN NSString *const UITextFieldTe ...