I am creating a Spring REST web service in java, that can be used by Android/IPhone. My method in the controller is following
@RequestMapping(method = RequestMethod.POST, value = "/registerUser")
public ModelAndView registerUser(@RequestBody User user,HttpServletRequest request){
//register user
}
I have an idea about Form based validations with Spring validators that are most-closely work with ModelAttribute in case of Spring Websites.
My question is that, How can i validate the user object, and send the specific error to Android/Iphone end? Say if username is not in email pattern , how can i send the error message specific to wrong username to Mobile ends, and how will they display that?
Thanks in advance.
I'd take a look at the JSR303 annotation driven bean validation stuff. This link will get you started:
http://www.hibernate.org/subprojects/validator.html
And also:
http://docs.jboss.org/hibernate/validator/4.2/reference/en-US/html_single/
There are also plenty of tutorials out there too.
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