SpringMVC中Model和ModelAndView的EL表达式取值方法

2025-05-29 0 27

modelmodelMap(spring 封装),Java.util.Map

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23
ModelMap(视图)

ModelAndView modelAndView = new ModelAndView();

modelAndView.addObject("name", "xxx");

modelAndView.setViewName("/user/index");

return modelAndView;

//对于ModelAndView构造函数可以指定返回页面的名称,也可以通过setViewName方法来设置所需要跳转的页面;

在前端用${name}调用

MODLE:

String retVal = "user/index";

User user = new User();

user.setName("XXX");

model.addAttribute("currentUser", user);

return retVal;

//通过addAttribute()添加属性,(假设user有name属性)在前端用${currentUser.name}调用

Map

ModelAndView mav = new ModelAndView();

User user1=new User();------假设User有name的属性

Map map=new HashMap();

map.put("user",user1);//map.put相当于request.setAttribute方法

mav.addObject(map);

mav.setViewName("qweqas");

return mav;;

//在前端用户${user.name}调用

以上这篇SpringMVC中Model和ModelAndViewEL表达式取值方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持快网idc。

原文链接:https://blog.csdn.net/yancychas/article/details/60138974

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 SpringMVC中Model和ModelAndView的EL表达式取值方法 https://www.kuaiidc.com/112446.html

相关文章

发表评论
暂无评论