Reputation: 3757
I want many of my controllers to create and return ModelMaps and to have these ModelMaps subsequently sent to/processed by a JsonView. (These controllers will service AJAX requests.) I assume I need setup a ViewResolver; what is the best way to do this? Is there a better alternative to Spring-Json View?
EDIT:
How do I wire a view when my controller returns ModelMap objects rather than ModelAndView objects?
Upvotes: 1
Views: 4822
Reputation: 3757
/**
* Custom handler for displaying vets.
* Note that this handler returns a plain {@link ModelMap} object instead of
* a ModelAndView, thus leveraging convention-based model attribute names.
* It relies on the RequestToViewNameTranslator to determine the logical
* view name based on the request URL: "/vets.do" -> "vets".
* @return a ModelMap with the model attributes for the view
*/
@RequestMapping("/vets.do")
public ModelMap vetsHandler() {
return new ModelMap(this.clinic.getVets());
}
It relies on the RequestToViewNameTranslator to determine the logical view name.
Upvotes: 1
Reputation: 140051
What is the problem with using spring-json view?
This seems like the exact way you would want to handle something like this:
Upvotes: 1