作用:

由于本身http是无状态的并不会保存什么请求信息。  但是目标页面可能又需要一些信息。这时候可以用ModelAndView存放一些业务数据之类等。然后返回给页面

用法:

比较重要的方法:

往对象里面加入变量

    /**
* Add an attribute to the model.
* @param attributeName name of the object to add to the model (never {@code null})
* @param attributeValue object to add to the model (can be {@code null})
* @see ModelMap#addAttribute(String, Object)
* @see #getModelMap()
*/
public ModelAndView addObject(String attributeName, @Nullable Object attributeValue) {
getModelMap().addAttribute(attributeName, attributeValue);
return this;
}

设置需要放回的页面

    /**
* Set a view name for this ModelAndView, to be resolved by the
* DispatcherServlet via a ViewResolver. Will override any
* pre-existing view name or View.
*/
public void setViewName(@Nullable String viewName) {
this.view = viewName;
}

使用:

 @RequestMapping("/findAll")
public ModelAndView accFindAll(){
ModelAndView mv = new ModelAndView();
System.out.println("springmvcdone1");
Account account = accountService.findAll();
mv.addObject("at",account);
mv.addObject("atmoney",account.getMoney());
mv.setViewName("list");
System.out.println("springmvcdone2");
return mv;
}

jsp:

<html>
<head>
<title>findAll</title>
</head>
<body>
${requestScope.atmoney}
${requestScope.at.toString()}
${requestScope.get("atmoney")}
</body>
</html>

如果上面的jsp没有获取到变量的值

可能的原因

${resquestScope.get(“param_name”)}
${resquestScope.atmoney} 访问结果是字符串,没有访问到变量
在于老的JSP 1.2 声明.
JSP 1.2
EL是默认关闭的必须手动打开。<%@ page isELIgnored="false" %>
但如果是JSP2.0版就可以直接用。
只需要在编译的JSP文件中头文件中加入:<%@ page isELIgnored="false" %>

最新文章

  1. Excel导入导出组件的设计
  2. Silverlight中将WriteableBitmap互转byte数组
  3. 理解Java接口
  4. C#判断一个string是否为数字
  5. PowerDesigner更改数据库类型
  6. POJ 1041问题描述
  7. Linux下常用的shell命令记录1
  8. mvc4 http错误403.14 forbidden
  9. Arduino报错
  10. 《openstack 和hadoop的区别是什么?》
  11. html向servlet传乱码解决办法
  12. elasticsearch的javaAPI之query
  13. VC 为静态控件添加事件
  14. CCLayer在Touch事件(Standard Touch Delegate和Targeted Touch Delegate)
  15. swift设置textfield边框颜色
  16. EclipseIDE--使用整理
  17. 201771010126 王燕《面向对象程序设计(Java)》第十三周学习总结
  18. vue+vuex 回退定位到初始位置
  19. day 36 网络编程终结内容
  20. openssl版本升级操作记录

热门文章

  1. 100G/40G/25G/10G网络测试解决方案
  2. 【C# .Net GC】垃圾回收算法 应用程序线程运行时,
  3. 【C# 基础概念】命名空间
  4. CVE-2022-22947 Spring Cloud Gateway SPEL RCE复现
  5. MySQL 学习-进阶
  6. pyqt(二)
  7. 矩池云上安装caffe gpu教程
  8. 二级py--day4 数据结构与算法篇
  9. LGP4451题解
  10. Source Code Reading for Vue 3: How does `hasChanged` work?