swagger遇到For input string: ""的报错

公司新项目使用了萧明大佬的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>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。