What I'd like to be able to do is write one method that will return an object, map the method to a request, and alter how the object is formatted based on the url. So, if I had an array of Client objects that get returned for /clients
, I'd like to, by default, resolve the object to a velocity template (clients.vm) to handle the formatting. However, if the url is /clients.json
, than I'd like to pass the object back in the response body, and let the message converter figure out how to handle it.
So, my question is, how do I configure Spring, and how do I write the controller?
Thx
Use a
PathVariable
in your handler method, use that to toggle which view to use:View type could be
vm
, orjsp
, or whatever. It could also return JSON if the return type is simply changed to@ResponseBody
and you have the Jackson JARs on the classpath.