公司新项目使用了萧明大佬的swagger加强版,
地址:https://github.com/xiaoymin/swagger-bootstrap-ui/blob/master/README_zh.md
打开文档时遇到 java.lang.NumberFormatException: For input string: "" 的异常,原因是swagger文档上每个参数都会设定一个默认值,包装类型的默认值是"",所以会出现转换异常。
解决方案:
方案1:在@ApiModelProperty设定默认值
@ApiModelProperty(value ="邮费", required =true, example ="0.00")
方案2:降低 springfox-swagger2 包中 swagger-annotations 和 swagger-models 的版本号
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
<exclusions>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.21</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.21</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>