我使用@Min(0)来验证表单输入是否为正整数或0,但在输入1.2时遇到了NumberFormatException。(我使用Spring Boot + Thymeleaf)
我做错了什么?
我的代码:
@Min(value = 0, message = "need zero or positive integer")
private int qty;当我输入-1时,我得到了我想要的消息,但是当我输入1.2时,我得到了NumberFormatException:
Failed to convert property value of type java.lang.String to required type int for property qty; nested exception is java.lang.NumberFormatException: For input string: "1.2"发布于 2020-05-31 16:42:39
import javax.validation.constraints.NotNull;
import javax.validation.constraints.PositiveOrZero;@NotNull(message = "Prop must be not null.")
@PositiveOrZero(message = "Prop value should zero or positive.")
private Integer prop;https://stackoverflow.com/questions/62113551
复制相似问题