开发者

Using Java Spring 3.0 @NumberFormat annotation

开发者 https://www.devze.com 2023-04-06 11:56 出处:网络
I\'m currently working on a small project trying to get Java spring validation working on a web form. It does work, however I have one input for inputting age, which I then convert to number format us

I'm currently working on a small project trying to get Java spring validation working on a web form. It does work, however I have one input for inputting age, which I then convert to number format using this annotation, if I input letters it causes this to be displayed next to the input box when the form is submitted:

"Failed to convert property value of type java.lang.String to required type java.lang.Integer for property age; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value "dasdf" from type java.lang.String to type java.lang.In开发者_Go百科teger; nested exception is java.lang.IllegalArgumentException: Unable to parse dasdf"

Is there any way to change this message, I'm sure it's simple, but have searched and can't find it.

This is the validation code currently:

@NotNull
@NumberFormat(style = Style.NUMBER)
@Min(1)        
@Max(110)        
private Integer age;

Cheers, David


I found the answer, inputting this into my messages.properties file overrides the default error message.

typeMismatch.age=Input should be a number

I knew it would be simple, but took a long time to find the syntax.

0

精彩评论

暂无评论...
验证码 换一张
取 消