Reputation: 2617
Code from a controller:
@Controller
public class HomeController {
@Autowired
private ItemService itemService;
@RequestMapping("/home")
public String showHomePage(Map<String, Object> model) {
model.put("items", itemService.getItems());
return "home";
}
}
And a part of the correspondent home.jsp:
<c:forEach items="${items}" var="item">
${item}
</c:forEach>
In a browser I get elements that are returned from itemService.getItems().
How Spring finds out that model
map contains values to be request attributes?
Upvotes: 2
Views: 79
Reputation: 28569
Does the DispatcherServlet copy contents of all parameters of type Map to request attributes?
Yes, Spring MVC copies all the parameters from model to HttpServletRequest object. The reason why Spring people chosen not to use the HttpServeltRequest directly, is due to the requirement that they want to be as independent from the view technologies as possible, so being able to drive the view technologies that don't depend on the HttpServeltRequest
Exposing the model as request parameters is a facet of view, and you'll find the appropriate code if you check out the source of SpringMVC's InternalResourceView which extends from AbstractView that holds the exposeModelAsRequestAttributes method
Upvotes: 1