Problem phenomenon:
In the process of learning swagger today, after starting the swaggerUI page, an error was reported in the background:
java.lang.NumberFormatException: For input string: ""
problem analysis:
This error means that the format of the integer data type is abnormal: an empty string is passed in to the integer data type, which causes the error.
By consulting online information, we can know:
This is because springfox-swagger2 (2.9.2) depends on swagger-models (1.5.20);
And this version of swagger will be entity class type of China-Africa String property defaults assigned to an empty string.
Therefore, you need to manually add a higher version of swagger-models dependency!!!!!!
So after starting the swaggerUI page, the non-String attribute of the entity class at this time has no default value, and NumberFormatException: For input string: "" will appear.
Solution:
<!--swaggerUI-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
Just add the dependency of swagger-models (1.5.21) :
<!--swaggerUI-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!--规范model实体类注解-->
<!--如果不加,则当实体类非String属性没有默认值时,会出现NumberFormatException: For input string:"",
这是因为springfox-swagger2(2.9.2)依赖于swagger-models(1.5.20)
该版本的swagger只判断了null没有判断空字串符
所以会将实体类中非String类型的属性默认赋值为空字符串;
而1.5.21版本之后新增了空串判断,所以就不会有该问题了-->
<!--<dependency>-->
<!--<groupId>io.swagger</groupId>-->
<!--<artifactId>swagger-models</artifactId>-->
<!--<version>1.5.21</version>-->
<!--</dependency>-->
Restart, no more errors: