springboot 集成swagger
了解到swagger 就记录下用法
rest.swaggerEnabled 配置文件设置为true开启swagger,false或者不配置,不开启swagger
pom.xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
Swagger2.java
package com.zjjw.manager.web.config; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; /**
* Swagger的配置信息
*
* @author tzq
* @date 2019-03-18 16:11
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig { @Value("${rest.swaggerEnabled:false}")
private Boolean restConfig ; @Bean
public Docket docket() {
return new Docket(DocumentationType.SWAGGER_2)
.enable(restConfig)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.zjjw.manager.web.controller"))
.apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build();
} private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Cloud-Console API")
.description("检务后台管理API")
.version("1.0.0")
.build();
}
}
Controller注解
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; @RestController
@RequestMapping("test")
@Api(value="测试接口Controller")
public class TestController { @ApiOperation(value="测试用接口", notes="测试用接口" ,httpMethod="POST")
@ApiImplicitParams({
@ApiImplicitParam(name="name", value="用户姓名", dataType = "String", required=true, paramType="form"),
@ApiImplicitParam(name="id", value="id", dataType = "int", required=false, paramType="form")
})
@RequestMapping("word")
public String HelloWord(String name,Integer id) {
return "Hello Word";
}
访问路径:ip+端口/swagger-ui.html
swagger 个人感觉,适合快速开发,减少些接口文档的时间,
springboot 集成swagger的更多相关文章
- spring-boot 集成 swagger 问题的解决
spring-boot 集成 swagger 网上有许多关于 spring boot 集成 swagger 的教程.按照教程去做,发现无法打开接口界面. 项目由 spring mvc 迁移过来,是一个 ...
- 20190909 SpringBoot集成Swagger
SpringBoot集成Swagger 1. 引入依赖 // SpringBoot compile('org.springframework.boot:spring-boot-starter-web' ...
- SpringBoot集成Swagger,Postman,newman,jenkins自动化测试.
环境:Spring Boot,Swagger,gradle,Postman,newman,jenkins SpringBoot环境搭建. Swagger简介 Swagger 是一款RESTFUL接口的 ...
- springboot集成swagger添加消息头(header请求头信息)
springboot集成swagger上篇文章介绍: https://blog.csdn.net/qiaorui_/article/details/80435488 添加头信息: package co ...
- springboot 集成 swagger 自动生成API文档
Swagger是一个规范和完整的框架,用于生成.描述.调用和可视化RESTful风格的Web服务.简单来说,Swagger是一个功能强大的接口管理工具,并且提供了多种编程语言的前后端分离解决方案. S ...
- SpringBoot集成Swagger接口管理工具
手写Api文档的几个痛点: 文档需要更新的时候,需要再次发送一份给前端,也就是文档更新交流不及时. 接口返回结果不明确 不能直接在线测试接口,通常需要使用工具,比如postman 接口文档太多,不好管 ...
- springboot 集成swagger ui
springboot 配置swagger ui 1. 添加依赖 <!-- swagger ui --> <dependency> <groupId>io.sprin ...
- springboot集成swagger实战(基础版)
1. 前言说明 本文主要介绍springboot整合swagger的全过程,从开始的swagger到Knife4j的进阶之路:Knife4j是swagger-bootstarp-ui的升级版,包括一些 ...
- springboot集成swagger
对于搬砖的同学来说,写接口容易,写接口文档很烦,接口变动,维护接口文档就更更更烦,所以经常能发现文档与程序不匹配. 等过一段时间就连开发者也蒙圈了 Swagger2快速方便的解决了以上问题.一个能与S ...
- springboot集成swagger文档
//此处省略springboot创建过程 1.引入swagger相关依赖(2个依赖必须版本相同) <dependency> <groupId>io.springfox</ ...
随机推荐
- 解决Azure 消息队列ServiceBus提示证书不信任无权限的问题
笔者在C# 消息队列-Microsoft Azure service bus 服务总线中使用Azure消息队列,最近偶尔会遇到请求数据不入队列的问题,查找日志,问题如下: 异常:X. certific ...
- CSS代码片段
定位: 将元素居中 将元素水平居中 将元素垂直居中 样式: 文字毛玻璃效果 -------------------------------------------代码----------------- ...
- [翻译]:MySQL Error: Too many connections
翻译:MySQL Error: Too many connections 前言: 本文是对Muhammad Irfan的这篇博客MySQL Error: Too many connections的 ...
- linux $参数
$# 是传给脚本的参数个数 $0 是脚本本身的名字 $1 是传递给该shell脚本的第一个参数 $2 是传递给该shell脚本的第二个参数 $@ 是传给脚本的所有参数的列表 $* 是以一个单字符串显示 ...
- 解决Win10系统本地主机,网络受限占用CPU过高的问题
Win10版本为2015年第一个版本,第一次安装时没有这个问题,后面每次安装后开机正常,但是只要运行一段时间后(机子有运行各种软件的情况),发现CPU使用率为100% 即使结束所有在运行的程序,依然居 ...
- 面相服务的架构SOA
SOA体系结构是基于服务组件模型,将应用程序的不同功能单元通过定义良好的接口契约联系起来,接口是采用中立方式进行定义的,独立于实现服务的硬件平台,操作系统和编程语言.使得构建在这样的系统中的服务可以以 ...
- python3打印当前时间和获取程序运行时间
学习使用time模块和datetime模块. 通常我们想让程序等待几秒钟,再继续向下运行,time模块的sleep()方法是一个很好的选择.但是想通过time模块打印系统的当前时间,则比较麻烦.如下: ...
- Linux之Samba部署
1.Samba介绍 Samba 是在 Linux 和 UNIX 系统上实现 SMB 协议的一个免费软件,由服务器及客户端程序构成,SMB(Server Messages Block,信息服务块)是一种 ...
- SQLServer之DEFAULT约束
DEFAULT约束添加规则 1.若在表中定义了默认值约束,用户在插入新的数据行时,如果该行没有指定数据,那么系统将默认值赋给该列,如果我们不设置默认值,系统默认为NULL. 2.如果“默认值”字段中的 ...
- LeetCode算法题-Quad Tree Intersection(Java实现)
这是悦乐书的第260次更新,第273篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第127题(顺位题号是558).四叉树是树数据,其中每个内部节点恰好有四个子节点:top ...