When I input alphabets such as "adsf
" in the input field, spring tries to bind it to my price( a double) property of my "Code" object and this causes the bind exception. What can I do to avoid this error, if I wanted to keep the field as a double?
POJO
@entity
@Table(name=“CODE”)
public class Code{
@Column(name=“PRICE”)
@NotNull
@DecimalMax(value=“999999999999.999999”)
@DemimalMin(value=“0.0”)
private Double price;
//getters and setters
}
My controller
@RequestMapping(value=“validateField”, method=RequestMethod.POST, produces=“application/json”)
public FieldValidatinResult validateField(final Code code, final String field){
//return statement
}
html page
<input type=“text” class=“form-control validatable” id=“price”></input>
Error message:
Field error in object ‘code’ on field ‘price’: rejected value [adsf];
codes[typeMismatch.code.price,typeMismatch.price,typeMismatch.java.lang.Double,typeMismatch]; arguments[org.springframework.context.support.DefaultMessageSourceResolvable:
codes [code.price,price]; arguments []; default message [price]]; default message
[Failed to convert property value of type 'java.lang.String' to required type
'java.lang.Double' for property 'price'; nested exception is
java.lang.NumberFormatException: For input string: "adsf"]
Aucun commentaire:
Enregistrer un commentaire