打开或者swagger文档控制台出现For input string: ““的报错

出现原因

是因为swagger文档上每个参数都会设定一个默认值,包装类型的默认值是"",所以会出现转换异常。

解决方案
方案一

在@ApiModelProperty设定默认值

方案二

降低 springfox-swagger2 包中 swagger-annotations 和 swagger-models 的版本号

	<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
            <exclusions>
             <!--屏蔽旧版本的swagger-annotations-->
                <exclusion>
                    <groupId>io.swagger</groupId>
                    <artifactId>swagger-annotations</artifactId>
                </exclusion>
                <!--屏蔽旧版本的swagger-models-->
                <exclusion>
                    <groupId>io.swagger</groupId>
                    <artifactId>swagger-models</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--引入指定版本的swagger-annotations和swagger-models解决出现加载swagger时候For input string: ““问题-->
        <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>

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
回答: 这个报错是由于Swagger2中的@ApiModelProperties注解没有指定example的值而产生的。如果example的值被默认设置为"",在后续处理过程中,Swagger会尝试将空字符串转换为数字,从而导致NumberFormatException异常的抛出。这实际上是Swagger2的一个bug。为了解决这个问题,你可以更新你的Swagger依赖版本到2.8.0,并确保在pom.xml文件中添加以下依赖项: ``` <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.8.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.8.0</version> </dependency> ``` 这样做应该能够解决你遇到的问题。\[2\]\[3\] #### 引用[.reference_title] - *1* *2* [swagger2.9.2 报错 For input string: “” 解决方法](https://blog.csdn.net/weixin_45630446/article/details/115824063)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [控制台报错For input string: ““、empty String](https://blog.csdn.net/m0_54193189/article/details/124022198)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lemon20120331

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值