zoukankan      html  css  js  c++  java
  • Swagger2异常:Illegal DefaultValue null for parameter type integer java

    一、异常分析:

    Illegal DefaultValue null for parameter type integer`和`NumberFormatException: For input string: ""

    从上面这句可以看出,有个默认值是空字符串的变量转换成Integer类型时异常。

    at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412) ~[swagger-models-1.5.20.jar:1.5.20]

    根据上面这句报错信息,点进去AbstractSerializableParameter.java:412可以看到

    if(BaseIntegerProperty.TYPE.equals(type)){

        return Long.valueOf(example);

    }

    就是说如果实体属性类型是Integer,就把example转为Long类型,而example默认为"",导致转换错误。

    二、解决办法:

    方法一:
    实体类中,Integer类型的属性加@ApiModelProperty时,必须要给example参数赋值,且值必须为数字类型。

    @ApiModelProperty(value = "试卷ID",example = "1")
    private int pageId;
    

      

    方法二:

    忽略原版本的swagger-annotations和swagger-models,添加1.5.21版本的

    <!--swagger依赖-->
    
    <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>
    
    <!--解决进入swagger页面报类型转换错误,排除2.9.2中的引用,手动增加1.5.21版本-->
    
    <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>
    

      

  • 相关阅读:
    数码管模块
    iis报mmc检测错误解决办法
    图片显示加时间戳
    C#.Net上传文件大小限制设置
    DoNet 打包,能够自动生成数据库(可以执行某些exe,vbs文件)
    aspx模式窗口
    aspx页面不能及时更新数据
    aspx 页面提交造成页面样式混乱
    MSSQL中返回刚插入记录的ID
    修改SQL数据库中表字段类型时,报“一个或多个对象访问此列”错误的解决方法
  • 原文地址:https://www.cnblogs.com/ampl/p/11426687.html
Copyright © 2011-2022 走看看