SpringBoot集成Swagger2实现Restful(类型转换错误解决办法)
来源:互联网 发布:搜狗删除 云计算 编辑:程序博客网 时间:2024/05/16 12:12
pom.xml增加依赖包
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.2.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.2.2</version> </dependency>
编写swapper2配置类
package com.springboot.config;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;@Configuration//该注解实现让spring知道这个是配置的类@EnableSwagger2//注解来启用Swagger2public class Swagger2 { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.springboot.ctrl")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("Spring Boot中使用Swagger2构建RESTful APIs") .description("description") .termsOfServiceUrl("termsOfServiceUrl") .contact("hp") .version("1.0") .build(); }}
Controller内使用
@ApiOperation(value = "更新用户详细信息", notes = "更新用户详细信息notes") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "ID", paramType = "path", required = true, dataType = "Long"), @ApiImplicitParam(name = "user", value = "user", required = true, dataType = "User") }) @RequestMapping(value = "/{id}", method = RequestMethod.PUT) public String putUser(@PathVariable Long id, @RequestBody User user) { User u = users.get(id); u.setName(user.getName()); u.setAge(user.getAge()); users.put(id, u); return "success"; }
如果上诉代码没有写paramType = “path” 会提示类型转换String convert to Long错误。
0 0
- SpringBoot集成Swagger2实现Restful(类型转换错误解决办法)
- SpringBoot集成Swagger2实现Restful(类型转换错误解决办法)
- SpringBoot集成springfox-swagger2构建restful API
- 【转】SpringBoot集成springfox-swagger2构建restful API
- springboot集成swagger2,构建优雅的Restful API doc
- Springboot集成swagger2
- springboot项目集成Swagger2
- SpringBoot集成Swagger2
- springboot集成swagger2
- springboot集成swagger2
- Springboot集成Swagger2
- SpringBoot集成Swagger2
- SpringBoot非官方教程 | 第十一篇:springboot集成swagger2,构建优雅的Restful API
- SpringBoot非官方教程 | 第十一篇:springboot集成swagger2,构建优雅的Restful API
- SpringBoot非官方教程 | 第十一篇:springboot集成swagger2,构建优雅的Restful API
- SpringBoot非官方教程 | 第十一篇:springboot集成swagger2,构建优雅的Restful API
- springboot-restful api-swagger2 ui-实战
- springboot-restful api-swagger2 ui-实战
- eclipse集成weblogic开发环境的搭建(转载自gaofuqi的专栏)
- 380. Insert Delete GetRandom O(1)--构造新类的题目
- flask安装
- HDU 1257 最少拦截系统(基础dp)
- javascript自定义弹窗
- SpringBoot集成Swagger2实现Restful(类型转换错误解决办法)
- 【有容云干货-容器系列】补脑专用,容器生态圈脑图大放送
- Fixed function Shader 1
- jenkins 主目录修改
- 吉祥坊WellBET成为意甲官方赞助商造假
- Java ConcurrentModificationException异常原因和解决方法
- RabbitMQ安装遇到的问题(转载)
- Volley使用
- bluestore调研