springboot中swaggerUI的使用

时间:2022-08-25 15:47:26

该文章已更新,请查看

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中swaggerUI的使用的更多相关文章

  1. SpringBoot整合Swagger-ui

    SpringBoot整合Swagger-ui 引入依赖 <dependency> <groupId>org.springframework.boot</groupId&g ...

  2. 如何让接口文档自动生成,SpringBoot中Swagger的使用

    目录 一.在SpringBoot项目中配置Swagger2 1.pom.xml中对Swagger2的依赖 2.编写配置类启用Swagger 3.配置实体类的文档 4.配置接口的文档 5.访问文档 二. ...

  3. SpringBoot中yaml配置对象

    转载请在页首注明作者与出处 一:前言 YAML可以代替传统的xx.properties文件,但是它支持声明map,数组,list,字符串,boolean值,数值,NULL,日期,基本满足开发过程中的所 ...

  4. 如何在SpringBoot中使用JSP ?但强烈不推荐,果断改Themeleaf吧

    做WEB项目,一定都用过JSP这个大牌.Spring MVC里面也可以很方便的将JSP与一个View关联起来,使用还是非常方便的.当你从一个传统的Spring MVC项目转入一个Spring Boot ...

  5. spring-boot&plus;mybatis开发实战:如何在spring-boot中使用myabtis持久层框架

    前言: 本项目基于maven构建,使用mybatis-spring-boot作为spring-boot项目的持久层框架 spring-boot中使用mybatis持久层框架与原spring项目使用方式 ...

  6. 由浅入深学习springboot中使用redis

    很多时候,我们会在springboot中配置redis,但是就那么几个配置就配好了,没办法知道为什么,这里就详细的讲解一下 这里假设已经成功创建了一个springboot项目. redis连接工厂类 ...

  7. Springboot中使用AOP统一处理Web请求日志

    title: Springboot中使用AOP统一处理Web请求日志 date: 2017-04-26 16:30:48 tags: ['Spring Boot','AOP'] categories: ...

  8. SpringBoot 中常用注解

    本篇博文将介绍几种SpringBoot 中常用注解 其中,各注解的作用为: @PathVaribale 获取url中的数据 @RequestParam 获取请求参数的值 @GetMapping 组合注 ...

  9. SpringBoot中关于Mybatis使用的三个问题

    SpringBoot中关于Mybatis使用的三个问题 转载请注明源地址:http://www.cnblogs.com/funnyzpc/p/8495453.html 原本是要讲讲PostgreSQL ...

随机推荐

  1. simvision1 database和invoke

    VCD是一种ASCII码的文件,可以直接用gvim来打开.有两种格式:1)Four-state,  2) Extended, 相比较而言,Extended VCD会多一些strength的信息. VC ...

  2. Android WebView 实现缓存网页数据

    WebView中存在着两种缓存:网页数据缓存(存储打开过的页面及资源),H5缓存(即AppCache). 将我们浏览过的网页url已经网页文件(css.图片.js等)保存到数据库表中 缓存模式(5种) ...

  3. 信息传递--NOIP2015 day1 T2--暴力

    这道题我用了判联通量加暴力,但联通量判炸了....然后从code[VS]上看到个不错的代码,就拿来了^_^... 基本思路是去掉环外的点,然后走每一个联通块. #include <iostrea ...

  4. rpm -qs查看包信息

    rpm -qs mysql-connector-c-devel Query options (with -q or --query):  -c, --configfiles               ...

  5. input 上传图片显示预览、调用摄像头,ios和Android的兼容性解决

    html代码: <img id="pic" src="img/pic.png"/> </span><input id=" ...

  6. jQuery中height&lpar;&rpar;不能精确计算的问题

    jQuery中关于高度的计算有三个方法:outerHeight().innerHeight().height() outerHeight():获取元素集合中第一个元素的当前计算高度值,包括paddin ...

  7. gcc 中&lowbar;&lowbar;thread 关键字的示例代码

    __thread 关键字的解释:   Thread Local Storage  线程局部存储(tls)是一种机制,通过这一机制分配的变量,每个当前线程有一个该变量的实例. gcc用于实现tls的运行 ...

  8. 多线程三:Task

    Task是.NET 3.0中推出的,是基于ThreadPool封装的,里面的线程都是来自于ThreadPool. 1.使用Run()方法启动线程 F12查看Run()方法的定义: 发现Run()方法的 ...

  9. 数据仓库基础(十二)Informatica组件(2)

    本文转载自:http://www.cnblogs.com/evencao/p/3152708.html 1.Router Transformation:在filter 组件中只能写一个过滤条件.而在R ...

  10. 转载 -- Cocoapod方式引入百川SDK -报错&lbrack;&excl;&rsqb; Unable to find a specification for &grave;xxx&grave;

    [cocopad集成百川sdk官网] iOS需要填写BundleID .BundleID要是当前应用的BundleID.勾选淘宝登录基础包下载SDK. 注意事项:将下载的SDK中的身份图片yw_122 ...