so lets say I have some model class:
public class MyRequestParams {
private Long val = Long.valueOf(0); // default value
// ... plus some other stuff
}
And what I want, is if the user provides http://host/path?val=& OR http://host/path?val=abc , which is invalid params, I don't want it to fail. I want it to just apply the default. I'm not sure how to do this at the moment except for storing val as a string and doing any checks to apply the default myself. Is there some easy way while keeping the type == Long?
Not tested, but you could register a custom editor for your property, using registerCustomEditor
, in a method annotated with @InitBinder
. This editor would simply return the default long value.
See http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/validation.html for documentation and examples.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.