一、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整合的更多相关文章

  1. SpringMVC中使用Swagger2整合

    Swagger2是什么 Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件. Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 W ...

  2. MP实战系列(十)之SpringMVC集成SpringFox+Swagger2

    该示例基于之前的实战系列,如果公司框架是使用JDK7以上及其Spring+MyBatis+SpringMVC/Spring+MyBatis Plus+SpringMVC可直接参考该实例. 不过建议最好 ...

  3. 使用springfox+swagger2书写API文档(十八)

    使用springfox+swagger2书写API文档 springfox是通过注解的形式自动生成API文档,利用它,可以很方便的书写restful API,swagger主要用于展示springfo ...

  4. SpringBoot与Swagger2整合

    一.Swagger简介与优势 相信各位在公司写API文档数量应该不少,当然如果你还处在自己一个人开发前后台的年代,当我没说,如今为了前后台更好的对接,还为了以后交接方便,都有要求写API文档. Swa ...

  5. swagger-ui 系统配置过程(基于spring+springmvc+swagger+springfox配置 web-api 管理系统)

    web工程部分框架信息:spring springmvc swagger springfox maven 参考文档:https://www.cnblogs.com/exmyth/p/7183753.h ...

  6. 1.springMVC+spring+Mybatis的整合思路

    SSM整合的过程:就是把一些东西交给spring管理,也就是添加配置文件的一个过程.那么有哪些东西我们要交给spring管理呢?大概有以下几个: 1.数据源(可配置数据库连接池) 2.SqlSessi ...

  7. SSM框架整合的详细过程(含每一步的分析及代码)。实质上是SpringMVC与mybatis的整合,应为spring与SpringMVC不需要整合。

    为了更好的学习 springmvc和mybatis整合开发的方法,需要将springmvc和mybatis进行整合. 整合目标:控制层采用springmvc.持久层使用mybatis实现. 1.1 需 ...

  8. Spring+SpringMVC+MyBatis+Maven框架整合

    本文记录了Spring+SpringMVC+MyBatis+Maven框架整合的记录,主要记录以下几点 一.Maven需要引入的jar包 二.Spring与SpringMVC的配置分离 三.Sprin ...

  9. SpringMVC:学习笔记(10)——整合Ckeditor且实现图片上传

    SpringMVC:学习笔记(10)——整合Ckeditor且实现图片上传 配置CKEDITOR 精简文件 解压之后可以看到ckeditor/lang下面有很多语言的js,如果不需要那么多种语言的,可 ...

  10. JavaWeb_(SpringMVC框架)测试SpringMVC&Spring&MyBatis三大整合

    搭建 SpringMVC&Spring&MyBatis三大整合 传送门 1.准备 测试搭建S pringMVC&Spring&MyBatis三大整合 用例   a)准备 ...

随机推荐

  1. php 转义html标签 反转html标签 符号

    $a = '<strong>123</strong>';     //假设这是html代码$b =  htmlspecialchars($a);          //将< ...

  2. ios开发知识点补充

    一:self class,self superClass  super class  super superClass 的区别 新建SubPerson继承person,在SubPerson中打印如下: ...

  3. 远离“精神乞丐”(IBM的前CEO郭士纳把员工分为四种类型)

    语音丨吴伯凡 乞丐与其说是一种身份, 不如说是一种精神状态, 习惯性索取且心安理得, 习惯性寻求安慰,习惯性抱怨, 与之截然对立的, 是“操之在我”(Proactive)的精神, 乞丐型员工是公司内部 ...

  4. tplink-如何远程WEB管理路由器?

    http://service.tp-link.com.cn/detail_article_185.html 如何远程WEB管理路由器? 新版tplink怎么远程Web管理? https://www.1 ...

  5. Stacks of Flapjacks

    Stacks of Flapjacks Background Stacks and Queues are often considered the bread and butter of data s ...

  6. Erlang 进制转换

    http://www.cnblogs.com/me-sa/archive/2012/03/20/erlang0047.html bnot unary bitwise not integer div i ...

  7. 【OpenGL】Shader实例分析(六)- 卡牌特效

    转发请保持地址:http://blog.csdn.net/stalendp/article/details/30989295 本文将介绍怎么通过alpha通道来隐藏信息.并实现卡牌特效. 执行效果例如 ...

  8. 使用Akka、Kafka和ElasticSearch等构建分析引擎 -- good

    本文翻译自Building Analytics Engine Using Akka, Kafka & ElasticSearch,已获得原作者Satendra Kumar和网站授权. 在这篇文 ...

  9. CORDOVA :添加cordova-plugin-file-opener2插件cordova打包报错

    原文:CORDOVA :添加cordova-plugin-file-opener2插件cordova打包报错 最近在接触android项目,其中涉及到APP自动更新的问题,当新APP下载成功后需要打开 ...

  10. 【23.15%】【codeforces 703C】Chris and Road

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...