Reputation: 1348
I am using spring mvc with Annotations, see the following snippet
@RequestMapping(value = "/configuration/", method = RequestMethod.GET)
public MyModel viewConfiguration() {
The problem I am having accessing the 'MyModel' class in my JSP.
How can I do this, without using the ModelAndView object?
Upvotes: 0
Views: 1753
Reputation: 242706
This shorthand syntax means that MyModel
becomes a model attribute named myModel
(i.e. class name with the first letter decapitalized).
View name is inferred from the URL.
See also:
Upvotes: 1
Reputation: 40178
You could set MyModel
as a request attribute to be accessed in your JSP. I'm curious, why don't you want to use ModelAndView
? After all, it does what you want to do here, which displays the view and provides a container to hold your objects you want to reference in your view.
By the way, if this is an Ajax call, you will need to add @ResponseBody
to the API so that your javascript can read the response in the callback function:-
@RequestMapping(value = "/configuration/", method = RequestMethod.GET)
public @ResponseBody MyModel viewConfiguration() {
...
}
Upvotes: 0