代码:

package com.gaussic.controller;

import com.gaussic.model.AccountModel;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView; import java.util.Arrays;
import java.util.Map;
import java.util.Date; /**
* Created by Administrator on 2016/9/9 0009.
*/
@Controller
@RequestMapping(value = "/test")
public class TestController {
@RequestMapping("/test")
public String test(Map<String,Object> map,Model model,ModelMap modelMap){
map.put("names", Arrays.asList("caoyc","zhh","cjx"));
model.addAttribute("time", new Date());
modelMap.addAttribute("city", "ChengDu");
modelMap.put("gender", "male");
return "/test/hello";
} @RequestMapping(value="/index", method = {RequestMethod.GET})
public ModelAndView index(){
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("message", "Hello World!");
modelAndView.setViewName("/test/index");
return modelAndView;
}
}

前端:

hello.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
1 1、time:${requestScope.time}
2 <br/>2、names:${requestScope.names }
3 <br/>3、city:${requestScope.city }
4 <br/>4、gender:${requestScope.gender }
</body>
</html>

index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
${message}
</body>
</html>

都可以向视图层传递参数

ModelAndView还可以指定跳转路径

http://blog.csdn.net/maoyeqiu/article/details/49717763

SpringMVC Map Model ModelMap 和 ModelAndView的更多相关文章

  1. springMVC Model ModelMap 和 ModelAndView的区别(转)

    原文地址:springMVC Model ModelMap 和 ModelAndView的区别 近来在看代码,发现controller里有不同的处理返回数据的方式,而自己一直在用ModelAndVie ...

  2. Spring中Model,ModelMap以及ModelAndView之间的区别

    原文链接:http://blog.csdn.net/zhangxing52077/article/details/75193948 Spring中Model,ModelMap以及ModelAndVie ...

  3. Model/ModelMap 和 ModelAndView 的区别使用

    Model/ModelMap 和 ModelAndView 的区别使用 Model/ModelMap controller: package springmvc.controller; import ...

  4. springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序

    springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序 http://www.360doc.com/content/14/03 ...

  5. springMVC数据模型model,modelmap,map,@ModelAttribute的相互关系

    结论: a.注解方法中形参为model,modelmap,map一个或几个时,他们指向的引用对象相同即他们的值相同. b.当使用@ModelAttribute注解请求参数时,springmvc自动将该 ...

  6. spring学习之springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序

    spring mvc处理方法支持如下的返回方式:ModelAndView, Model, ModelMap, Map,View, String, void.下面将对具体的一一进行说明: ModelAn ...

  7. SpringMVC学习 -- ModelAndView , Model , ModelMap , Map 及 @SessionAttributes 的使用

    输出模型数据: ModelAndView:处理方法返回值类型为 ModelAndView 时 , 其中包含视图和模型信息.方法体即可通过该对象添加模型数据 , 即 SpringMVC 会把 Model ...

  8. ModelAndView存取数Model、Map、ModelMap

    1.从名字上看ModelAndView中的Model代表模型,View代表视图,这个名字就很好地解释了该类的作用.(对应mvc配置,寻找模型,返回视图.) 2.业务处理器调用模型层处理完用户请求后,把 ...

  9. Spring MVC 向页面传值-Map、Model、ModelMap、ModelAndView

    Spring MVC 向页面传值,有4种方式: ModelAndView Map Model ModelMap 使用后面3种方式,都是在方法参数中,指定一个该类型的参数. Model Model 是一 ...

随机推荐

  1. APT 常用功能

    apt-get install package 安装包 apt-get reinstall package 重新安装包 apt-get upgrade 更新已安装的包 #apt-get update ...

  2. [GE]导入图片至Word,然后按规则命名(2/2)

    #将所有docx文件改成可读 Set-ItemProperty -Path "e:\screenshot\*.docx" -Name IsReadOnly -Value $fals ...

  3. Office 2010 KMS激活原理和案例分享 - Your Office Solution Here - Site Home - TechNet Blogs

    [作者:葛伟华.张玉工程师 ,  Office/Project支持团队, 微软亚太区全球技术支持中心 ] 为了减低部署盗版(可能包含恶意软件.病毒和其他安全风险)的可能性,Office 2010面向企 ...

  4. activeform 配置

    <?php $form = ActiveForm::begin([ 'action' => ['/admin/admin/adminadd'], 'id' => 'login-for ...

  5. CSS3:渐变大全

    渐变大全 声明 最后的老写法镜像渐变可能不太准确.其余都完全正确 <!DOCTYPE html> <html> <head> <meta http-equiv ...

  6. [办公自动化]如何对Excel表格顶部设计

    领导有一个excel要完成如下功能:顶部要包含企业LOGO,还要包含设计图号.版次等表格,还要包含类似“第  页 of  页” 总体思路: 1.利用顶端标题行完成除了页码以外的所有事情:(当然也可以利 ...

  7. Hibernate + proxool 连接数超过最大允许连接数

    主要原因是操作完成没有释放连接,在Hibernate中增加设定 <prop key="hibernate.connection.release_mode">after_ ...

  8. mysql查询所有字段(*),并且联表时需要特别注意的地方

    如果不标明*是读取哪个表,确实会将所有三个表都读出来.需要小心

  9. LR中的C语言问题

    今天在调试LR的脚本(C)时遇到了几个甚是头痛得问题,下面简单总结下: 1.首先LR中的C编译器遵循C90标准,规定在一个函数中,变量定义必须放在所有的执行语句之前!一旦在运行语句之间再有定义的话,会 ...

  10. php常用[字符串]函数

    nl2br 功能:化换行符为<br> <?php $str = "cat isn't \n dog"; $result = nl2br($str); echo $ ...