Reputation: 71
how does internalresourceviewresolver work, when my controller class does not return a modelandview object? how does it map to views?
here is the code snippet from the controller class:
@RequestMapping(value = "/abc", method = RequestMethod.GET)
public @ResponseBody
List<Map<String, Object>> getabc()
{
return jdbcDa.abc();
}
and here is the code snippet from dispatcher servlet:
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
Upvotes: 2
Views: 1568
Reputation: 482
Your method was annotated by @ResponseBody
, so the method will convert the List<Map<String, Object>>
to JSON, and wouldn't map to the view.
If you want to map the date to view, you can use AJAX request date from this interface @RequestMapping(value = "/abc", method = RequestMethod.GET)
, and use Javascript to show the date on the view. Just like this fragment:
$.getJSON('/abc', function (date) {
var s = "";
$.each(date, function (i, obj) {
//use javascript to add date to variable s
});
//add s to view element
$("#tag-list").append(s);
});
Upvotes: 0
Reputation: 47290
The internal view resolver is not involved here, you have annotated with @ResponseBody
and the method does not return a string/view name.
The returned data doesn't get mapped to a view. It is converted to json or xml depending on the content type of original request.
A method annotated with @ResponseBody
would normally be called asynchronously using javascript, the returned data would then, in a web app, be added to a specific part of the dom.
Upvotes: 1