Spring boot 整合Swagger的两种方式
2017-11-24 23:07
801 查看
增加请求不被拦截
,"/swagger-ui.html"
,"/swagger-resources/**"
方式1:
配置POM.xml
开启swagger
方式2:
添加yml配置
访问对应接口即可--------------------------至此已配置完毕
配置为@RequestBody
在实体类中添加注解
页面中显示注解
,"/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 @EnableSwagger2 public 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@
访问对应接口即可--------------------------至此已配置完毕
配置为@RequestBody
@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;
页面中显示注解
相关文章推荐
- SpringTest框架整合JUnit单元测试两种方式
- struts 与spring整合两种方式
- SpringBoot整合Swagger
- Spring boot和dubbo整合——基于传统方式
- websocket的两种实现方式:1基于注解,2与spring整合
- Spring整合Struts的两种方式介绍
- struts2+spring的两种整合方式
- 通过IntelliJ IDEA创建spring boot 项目的两种方式之方式一
- springboot 注册服务注册中心(zk)的两种方式
- Spring-boot中读取config配置文件的两种方式
- Spring-boot中读取config配置文件的两种方式
- 使用springfox整合Springboot和Swagger
- SpringBoot之Servlet定义的两种方式-yellowcong
- SpringBoot系列十一:SpringBoot整合Restful架构(使用 RestTemplate 模版实现 Rest 服务调用、Swagger 集成、动态修改日志级别)
- struts2、spring、hibernate整合jquery的json传值接收值的两种方式
- Swagger(一) SpringBoot整合Swagger2简单的例子
- Spring Boot 注解启动的两种方式
- 基于Maven的SpringBoot项目实现热部署的两种方式
- Struts2.1.8+Spring2.5.6+Hibernate3.2整合的两种方式!!!
- 基于springboot搭建dubbo框架(注解和xml配置两种方式)