看了spring mvc的底层会发现,model数据最终还是写到HttpServletRequest属性中,只是model的写法更体现了MVC思想减少各层间耦合
写法:
- 1.request.setAttribute("name","glj");//把值存到request
- 2.modelMap.addAttribute("name","glj");//把值存到modelMap
- 3.model.addAttribute("name","glj");//把值存到model
- 4.request.getSession.setAttribute("name","glj");//把值存到Session,这个是先获取了session,然后在存值到session
在jsp获取值
- 1.request.getAttribute("name")/el表达式${requestScope.name}/${name}
- 2.${name}
- 3.${name}
- 4.request.getSession().getAttribute/el表达式${sessionScope.name}/${name}
最后,其实${name}对以上几种取值都适用的,只是优先级的区别罢了
而Model和ModelMap都是一样的吧...只是二者谁最后赋值,谁的优先级就越高,然后才到request最后session