I am really not sure if this is feasible using Spring 3.2 MVC.
My Controller has a method declared as below:
@RequestMapping(method = RequestMethod.GET)
You cannot set multiple status value for @ResponseStatus. One approach I can think of is to use @ExceptionHandler for response status which is not HttpStatus.OK
@RequestMapping(value = "login.htm", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
public ModelAndView login(@ModelAttribute Login login) {
if(loginIsValidCondition) {
//process login
//.....
return new ModelAndView(...);
}
else{
throw new InvalidLoginException();
}
}
@ExceptionHandler(InvalidLoginException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ModelAndView invalidLogin() {
//handle invalid login
//.....
return new ModelAndView(...);
}