springboot中swaggerUI的使用
该文章已更新,请查看:
http://www.cnblogs.com/yzlpersonal/p/6420507.html
demo地址:demo-swagger-springboot
springboot中swaggerUI的使用
1.pom文件中添加swagger依赖
2.从github项目中下载swaggerUI
然后把dist目录下的所有文件复制到springboot项目的webapp下面,修改index.html中的: url = "http://petstore.swagger.io/v2/swagger.json";为---------> url="http://localhost:8080/api-docs";
3.spring boot启动类
public static void main(String[] args) {
SpringApplication.run(IndexController.class,args);
}
/** 配置 swagger开始*/ private SpringSwaggerConfig springSwaggerConfig;
/**
* Required to autowire SpringSwaggerConfig
*/
@Autowired
public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {
this.springSwaggerConfig = springSwaggerConfig;
}
/**
* Every SwaggerSpringMvcPlugin bean is picked up by the swagger-mvc
* framework - allowing for multiple swagger groups i.e. same code base
* multiple swagger resource listings.
*/
@Bean
public SwaggerSpringMvcPlugin customImplementation() {
return new SwaggerSpringMvcPlugin(this.springSwaggerConfig).apiInfo(apiInfo()).includePatterns(".*?");
}
private ApiInfo apiInfo() {
ApiInfo apiInfo = new ApiInfo(
"测试接口文档(标题)", // App Service API
"这是一个描述信息。。。",
"termsOfServiceUrl",
"younaame@yourmail.com",
"2222222222222222222222222222",
"3333333333333333333333333333");
return apiInfo;
}
/** 配置 swagger结束*/
4. 添加测试rest接口类:
@RestController
public class HelloController {
@RequestMapping(value = "/hello")
@ApiOperation(value = "添加用户",httpMethod ="POST", response = User.class,notes = "HelloWorld")
public User hello(@ApiParam(required = true,name = "paramData",value = "用户信息 json 数据") String paramData){
User userBean = new User();
userBean.setName("测试用户"); userBean.setOtherInfo("其他信息"); return userBean; } }
5 访问http://localhost:8080/api-docs,返回:
{
"apiVersion": "1.0",
"apis": [
{
"description": "Basic Error Controller",
"path": "/default/basic-error-controller",
"position": 0
},
{
"description": "Hello Controller",
"path": "/default/hello-controller",
"position": 0
}
],
"authorizations": {
},
"info": {
"contact": "younaame@yourmail.com",
"description": "这是一个描述信息。。。",
"license": "2222222222222222222222222222",
"licenseUrl": "3333333333333333333333333333",
"termsOfServiceUrl": "termsOfServiceUrl",
"title": "测试接口文档(标题)"
},
"swaggerVersion": "1.2"
} 说明配置正确。 然后再访问:http://localhost:8080/swagger/index.html,查看restful风格接口信息和效果。

springboot中swaggerUI的使用的更多相关文章
- SpringBoot整合Swagger-ui
SpringBoot整合Swagger-ui 引入依赖 <dependency> <groupId>org.springframework.boot</groupId&g ...
- 如何让接口文档自动生成,SpringBoot中Swagger的使用
目录 一.在SpringBoot项目中配置Swagger2 1.pom.xml中对Swagger2的依赖 2.编写配置类启用Swagger 3.配置实体类的文档 4.配置接口的文档 5.访问文档 二. ...
- SpringBoot中yaml配置对象
转载请在页首注明作者与出处 一:前言 YAML可以代替传统的xx.properties文件,但是它支持声明map,数组,list,字符串,boolean值,数值,NULL,日期,基本满足开发过程中的所 ...
- 如何在SpringBoot中使用JSP ?但强烈不推荐,果断改Themeleaf吧
做WEB项目,一定都用过JSP这个大牌.Spring MVC里面也可以很方便的将JSP与一个View关联起来,使用还是非常方便的.当你从一个传统的Spring MVC项目转入一个Spring Boot ...
- spring-boot+mybatis开发实战:如何在spring-boot中使用myabtis持久层框架
前言: 本项目基于maven构建,使用mybatis-spring-boot作为spring-boot项目的持久层框架 spring-boot中使用mybatis持久层框架与原spring项目使用方式 ...
- 由浅入深学习springboot中使用redis
很多时候,我们会在springboot中配置redis,但是就那么几个配置就配好了,没办法知道为什么,这里就详细的讲解一下 这里假设已经成功创建了一个springboot项目. redis连接工厂类 ...
- Springboot中使用AOP统一处理Web请求日志
title: Springboot中使用AOP统一处理Web请求日志 date: 2017-04-26 16:30:48 tags: ['Spring Boot','AOP'] categories: ...
- SpringBoot 中常用注解
本篇博文将介绍几种SpringBoot 中常用注解 其中,各注解的作用为: @PathVaribale 获取url中的数据 @RequestParam 获取请求参数的值 @GetMapping 组合注 ...
- SpringBoot中关于Mybatis使用的三个问题
SpringBoot中关于Mybatis使用的三个问题 转载请注明源地址:http://www.cnblogs.com/funnyzpc/p/8495453.html 原本是要讲讲PostgreSQL ...
随机推荐
- 通过Chrome浏览器检测和优化页面
1.访问(http://www.cnblogs.com/viaiu/) 2.点击F12 前两步就在扯淡 3.点击Audits标签,进入测试界面 4.点击按钮开始检测 5.如下图可以进行页面加载资源的详 ...
- 利用zlib库进行zip解压
1:到zlib官网上下载zlib,本文下载的是1.2.8的版本. 2:进行./configure,然后make. 3:进入zlib库中的contrib/minizip/路径下make,生成的miniz ...
- Windows Phone 二、WP控件
- struts2中的jsp值传到后台action接收的三种方法
struts2中的Action接收表单传递过来的参数有3种方法: 如,登陆表单login.jsp: <form action="login" method="pos ...
- shell: bad interpreter: No such file or directory
执行shell脚本 错误提示如下: bash: ./back : bad interpreter:No such file or directory 因为操作系统是windows,在win ...
- CentOS6配置国内yum源
在安装完CentOS后为了加快安装.更新rpm包的速度.需要将yum源改为国内源,国内比较快的源有中科大.163.sohu源.下面修改为163源为例子: 首先进入源的配置目录:执行 cd /etc/y ...
- python for mysql
# -*- coding: utf-8 -*- '''python coded by written in 2016/8/31 Used for get win os log for each win ...
- GIT版本库回滚【图文版】
git 版本库回滚,在实际开发过程中总会遇得到 1. 先找出需要回滚的commitid git log -3 2. 重置本地版本库到指定commitid, 注意:本地改动将丢失 ...
- OC-02 如何设计类
1.确认类名 2.类的属性 3.功能行为 例子:类名:person 属性:height 行为:fight 例子:坦克发射3颗炮弹打中2架飞机 类:坦克.炮弹.飞机 把相同属性的对象抽象成一 ...
- [T-SQL]INSERT INTO SELECT 与 SELECT INTO FROM
1.INSERT INTO SELECT 语法:INSERT INTO Table2(field1,field2,...) select value1,value2,... from Table1 要 ...