My app uses javax validation for the salary field, which is int. With what annotation should I use it, to avoid the error message like that
Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'salary'; nested exception is java.lang.NumberFormatException: For input string: ""
My current implementation looks like this:
@Column(name = "salary", nullable = false)
@NotNull(message= "salary may not be empty")
@Range(min = 1)
private int salary;
I know that I can not use NotBlank for a int field, that leads to an error. How can I display the message "salary may not be empty" instead of the exception above, if the "string" is empty? Thanks
I suggest you to use the object type Integer
which can hold the null value itself.
@Column(name = "salary", nullable = false)
@NotNull(message= "salary may not be empty")
@Range(min = 1)
private Integer salary;
The above secures there will be always the salary
input that has a value and it's equal or greater than 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With