Spring boot 整合Swagger的两种方式
来源:互联网 发布:远程桌面软件 win7 编辑:程序博客网 时间:2024/05/23 11:18
增加请求不被拦截
,"/swagger-ui.html" ,"/swagger-resources/**"
方式1:
<dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>${swagger.version}</version></dependency><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>${swagger.version}</version></dependency>
配置POM.xml
<!--swagger--><swagger.version>2.2.2</swagger.version>
开启swagger
import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.web.context.request.async.DeferredResult;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;@Configuration@EnableSwagger2public class Swagger2Config { /** * UI页面显示信息 */ private final String SWAGGER2_API_BASEPACKAGE = "com.op.copyems.Controller"; private final String SWAGGER2_API_TITLE = "ms-API"; private final String SWAGGER2_API_DESCRIPTION = "com.op.copyems.Controller"; private final String SWAGGER2_API_CONTACT = "0000"; private final String SWAGGER2_API_VERSION = "1.0"; /** * createRestApi * * @return */ @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage(SWAGGER2_API_BASEPACKAGE)) .paths(PathSelectors.any()) .build(); } /** * apiInfo * @return */ private ApiInfo apiInfo() { return new ApiInfoBuilder() .title(SWAGGER2_API_TITLE) .description(SWAGGER2_API_DESCRIPTION) .contact(SWAGGER2_API_CONTACT) .version(SWAGGER2_API_VERSION) .build(); }}
方式2:
<dependency><groupId>com.spring4all</groupId><artifactId>spring-boot-starter-swagger</artifactId><version>${spring-boot-starter-swagger.version}</version></dependency>
添加yml配置
swagger: enabled: true title: oms-API description: API文档 base-package: com.op.copyems.Controller base-path: /** exclude-path: /error version: @project.version@
访问对应接口即可--------------------------至此已配置完毕
@RequestMapping(value="", method=RequestMethod.POST) public String post(@RequestBody Book book) { books.put(book.getId(), book); return "success"; }
在实体类中添加注解
public class Book { @ApiModelProperty("名字") private String name; @ApiModelProperty("价格") private String price; @ApiModelProperty("关联id") private Long id;
页面中显示注解
阅读全文
0 0
- Spring boot 整合Swagger的两种方式
- spring boot 整合swagger
- Spring boot 整合Swagger
- 使用Spring Boot的两种方式
- Spring 整合 Struts 的两种方式
- spring整合hibernate的两种方式
- struts2+spring的两种整合方式
- Struts2整合Spring的两种方式
- hibernate 整合spring的两种方式
- struts2整合spring的两种方式
- struts2+spring的两种整合方式
- struts2+spring的两种整合方式
- Spring整合Struts2的两种方式
- spring整合hibernate的两种方式
- Spring整合struts2的两种方式
- spring整合hibernate的两种方式
- Spring Boot整合Swagger框架示例项目。
- spring-boot-swagger整合springmvc学习
- 【牛客访谈】对话何俊林:腾讯百度华为搜狗和滴滴面试题汇总
- 【2017-11-24】想说几句话-怂之描述
- Android中使用SVG实现炫酷动画效果
- jpg 格式举例详解——非常详细
- NOIP2017 滚粗记
- Spring boot 整合Swagger的两种方式
- java转JSON串的几种方式
- linux定时任务整理说明
- 指针笔记
- 赋值 和复合赋值操作符
- Hessian庖丁解牛
- 多路复用模型之epoll
- linux中部分概念
- bolt:一个纯Go实现的KV数据库