In Spring MVC, is it possible to have different return types in one request handler method?
- by Bobo
For example, if a request succeeds, I will return a View ,if not, return a String indicating error message and set the content-type to either xml or json.
Based on what I read, seems like I should use "void" as the return type for handler methods. Check this out:
"void if the method handles the response itself (by writing the response content directly, declaring an
argument of type ServletResponse / HttpServletResponse for that purpose) or if the view
name is supposed to be implicitly determined through a RequestToViewNameTranslator (not
declaring a response argument in the handler method signature)."(Spring Framework reference).
What I dont understand is what " the view
name is supposed to be implicitly determined through a RequestToViewNameTranslator (not
declaring a response argument in the handler method signature)" means? Any anyone give me an example?