ModelAndView存取数Model、Map、ModelMap
1、从名字上看ModelAndView中的Model代表模型,View代表视图,这个名字就很好地解释了该类的作用。(对应mvc配置,寻找模型,返回视图。)
2、业务处理器调用模型层处理完用户请求后,把结果数据存储在该类的model属性中,把要返回的视图信息存储在该类的view属性中,
3、然后让该ModelAndView返回该Spring MVC框架。框架通过调用配置文件中定义的视图解析器,对该对象进行解析,
4、最后把结果数据显示在指定的页面上。
在DispatcherServlet将请求分发给Spring Controller之前,需要借助于Spring提供的HandlerMapping定位到具体的Controller。HandlerMapping是这样一种对象,它能够完成客户请求到Controller之间的映射。在Struts中,这种映射是通过struts-config.xml文件完成的。其中,Spring为Controller接口提供了若干实现,例如Spring默认使用的BeanNameUrlHandlerMapping。还有,SimpleUrlHandlerMapping,CommonsPathMapHandlerMapping。
EL表达式取数位置:
Model、Map、ModelMap以及ModelAndView:初始化由Spring创建以上对象。
${msg }=${requestScope.msg }=<%=request.getAttribute("msg")%>
${user.getName()}=${requestScope.user.getName()}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
@RequestMapping ( "/save.do" ) public ModelAndView save(User user){ System.out.println( "------------------" ); System.out.println( "name=" +user.getName()+ " age=" +user.getAge()); System.out.println( "------------------" ); ModelAndView mv = new ModelAndView( "success" ); mv.addObject( "msg" , "添加成功3" ); mv.addObject( "user" , user); return mv; } //直接在处理方法上声明ModelMap对象 springmvc会将ModelMap中的数据携带到前台 @RequestMapping ( "/show.do" ) public ModelAndView show(ModelMap map){ map.addAttribute( "msg" , "modelMap携带参数" ); return new ModelAndView( "success" ); } //直接在处理方法上声明ModelMap对象 springmvc会将ModelMap中的数据携带到前台 @RequestMapping ( "/show1.do" ) public ModelAndView show1(Model map){ map.addAttribute( "msg" , "modelMap携带参数1" ); return new ModelAndView( "success" ); } //直接在处理方法上声明request对象 @RequestMapping ( "/show2.do" ) public ModelAndView show2(HttpServletRequest req){ req.setAttribute( "msg" , "req携带参数" ); return new ModelAndView( "success" ); }
|
ModelAndView存取数Model、Map、ModelMap的更多相关文章
- SpringMVC ModelAndView、Map、Model、ModelMap
目标方法返回值可以是ModelAndView .Map.Model.ModelMap类型,但最根本还都是ModelAndView. 其中可以包含试图和模型信息. SpringMVC 会把ModelAn ...
- SpringMVC中Map、Model、ModelMap、ModelAndView之间的关系及区别
首先,在了解这三者之前,需要知道一点:SpringMVC在调用方法前会创建一个隐含的数据模型(Model),作为模型数据的存储容器, 成为”隐含模型”. 如果controller方法的参数为Moedl ...
- Spring中Model、ModelMap及ModelAndView之间的区别
Spring中Model.ModelMap及ModelAndView之间的区别 1. Model(org.springframework.ui.Model)Model是一个接口,包含addAttr ...
- Spring中Model,ModelMap和ModelAndView
目录 1.Model接口 2.ModelMap 3.ModelAndView 1.Model接口(org.springframework.ui.Model) Model是一个接口,包含addAttri ...
- Spring中Model、ModelMap及ModelAndView之间的区别+传递参数
org.springframework.ui.Model(接口)传递数据,Spring框架自动创建它的一个实现类,如BindingAwareModelMap org.springframework.u ...
- SPRING框架中ModelAndView、Model、ModelMap区别及详细分析
转载内容:http://www.cnblogs.com/google4y/p/3421017.html 1. Model Model 是一个接口, 其实现类为ExtendedModelMap,继承了M ...
- Spring MVC 向页面传值-Map、Model和ModelMap
原文链接:https://www.cnblogs.com/caoyc/p/5635878.html Spring MVC 向页面传值-Map.Model和ModelMap 除了使用ModelAndVi ...
- Spring框架中ModelAndView、Model、ModelMap的区别
转自:http://blog.csdn.net/liujiakunit/article/details/51733211 1. Model Model 是一个接口, 其实现类为ExtendedMode ...
- SpringMVC 向页面传值-Map、Model和ModelMap
除了使用ModelAndView方式外.还可以使用Map.Model和ModelMap来向前台页面传值 使用后面3种方式,都是在方法参数中,指定一个该类型的参数.例如: Java代码 @Request ...
随机推荐
- Flask设计带认证token的RESTful API接口[翻译]
上一篇文章, 使用python的Flask实现一个RESTful API服务器端 简单地演示了Flask实的现的api服务器,里面提到了因为无状态的原则,没有session cookies,如果访问 ...
- HDU1423 最长公共上升子序列LCIS
Problem Description This is a problem from ZOJ 2432.To make it easyer,you just need output the lengt ...
- hdu 4460spfa用map来实现
#include<stdio.h> #include<string.h> #include <iostream> #include <algorithm& ...
- Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'
Spring Security :HTTP Status 403-Invalid CSRF Token 'null' was found on the request parameter '_csrf ...
- WordPress升级错误:class-wp-filesystem-direct.php on line 122
错误描述:WordPress在后台进行版本升级时,出错,之后进入前台或者后台,都无法访问进入,错误信息如下:Warning: copy(/home/xxx/public_html/wordpress/ ...
- delphi操作xml学习笔记 之一 入门必读
Delphi 对XML的支持---TXMLDocument类 Delphi7 支持对XML文档的操作,可以通过TXMLDocument类来实现对XML文档的读写.可以利用TXMLDocum ...
- FTP操作类的使用
FTP(文件传输协议) FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为“文传协议”.用于Internet上的控制文件的双向传输.同时,它也是一个应用程序 ...
- 【Perl】perl正则表达式中的元字符、转义字符、量词及匹配方式
Linux平台上被广泛使用的正则表达式库PCRE - Perl-compatible regular expressions,从其名字即可知道,PCRE提供的是一套与Perl中相兼容的正则表达式. 元 ...
- BloomFilter学习
看大数据面试题,看到BloomFilter,找了篇文章学习一下: http://www.cnblogs.com/heaad/archive/2011/01/02/1924195.html Bloom ...
- java 返回json数据
Student st1 = new Student(1, "dg", 18, new Date()); Student st2 = new Student(2 ...