首页 技术 正文
技术 2022年11月18日
0 收藏 696 点赞 4,238 浏览 755 个字

org.springframework.ui.Model(接口)
传递数据,Spring框架自动创建它的一个实现类,如BindingAwareModelMap

org.springframework.ui.ModelMap(类)
传递数据,Spring框架自动创建modelmap的实例,并作为controller方法的参数传入,用户无需自己创建对象。
ModelMap对象主要用于把controller方法处理的数据传递到jsp界面,在controller方法中把jsp界面需要的数据放到ModelMap对象中即可。
它的作用类似request对象的setAttribute方法。在视图层通过request找到ModelMap中的数据。
Modelmap本身不能设置页面跳转的url,可以通过controller方法的返回值来设置跳转的url。

org.springframework.web.servlet.ModelAndView(类):
设置转向地址,;传递数据ModelAndView的实例是由用户手动创建的,这也是和ModelMap的一个区别,
controller方法的返回值如果是ModelAndView,则其即包含模型数据信息,又包含视图信息,
这样SpringMVC将使用包含的视图对模型数据进行渲染,可以简单地将模型数据看成一个Map<String, Object>对象。
使用addObject方法即可ModelAndView addObject(String attributeName, @Nullable Object attributeValue)

还可以使用Map、Model和ModelMap来向前台页面传参
Spring中Model、ModelMap及ModelAndView之间的区别+传递参数
使用HashMap传参
Spring中Model、ModelMap及ModelAndView之间的区别+传递参数

使用ModelAndView传参

Spring中Model、ModelMap及ModelAndView之间的区别+传递参数

使用request传参

Spring中Model、ModelMap及ModelAndView之间的区别+传递参数

使用session传参

Spring中Model、ModelMap及ModelAndView之间的区别+传递参数

 
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,118
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,590
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,435
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,206
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,842
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,927