spring MVC session传递model
来源:互联网 发布:js禁止浏览器刷新按钮 编辑:程序博客网 时间:2024/05/18 00:04
通过spring MVC提供的@SessionAttributes 可以通过将model存在session实现跨controller的model传递,实现方法:
在存和取的controller类上都要添加注解,例如:
@Controller@RequestMapping("/myController/demo1")@SessionAttributes("demoModel")public class Demo1Controller {.......//在某个处理方法中调用model.addAttribute("demoModel", demoModel);}
在取的controller中同样需要注解,例如:
@Controller@RequestMapping("/myController/demo2")@SessionAttributes("demoModel")public class Demo2Controller {.......//在某个处理方法参数中声明@ModelAttribute("demoModel") DemoModel demoModel}
值得注意的是如果采用了validator, 比如Demo1Controller中采用了针对xxModel的validator, 那么spring MVC会报错,类似target invalid,也就是说spring MVC对session中的model也进行了验证,尽管这个model并不是要验证的xxModel,解决方法是通过注解显式指明要验证的model,例如:
@InitBinder("xxModel") public void initBinder(WebDataBinder binder) { binder.setValidator(new xxModelValidator()); }
- spring MVC session传递model
- Understanding Spring MVC Model and Session Attributes
- 理解Spring MVC Model Attribute 和 Session Attribute
- 待翻译---- Understanding Spring MVC Model and Session Attributes
- 理解Spring MVC Model Attribute 和 Session Attribute
- Spring MVC Model Example
- spring mvc model
- spring mvc将Model中的内容加入到Session中(利用@SessionAttributes)
- spring mvc 使用session
- Spring Mvc 使用Session
- Spring MVC 使用Session
- Spring MVC 传递参数
- Spring MVC 参数传递
- Spring mvc 传递数组
- spring MVC 参数传递
- spring MVC参数传递
- Spring mvc 参数传递
- spring Model 传递参数的值
- CI9.2-字符串排序
- 顺序表删除和X相同的所有元素(C)
- MATLAB像素颜色的表达方式
- 推荐近年来印象最深的几本书 .
- 使用Excel背单词-高效-简单
- spring MVC session传递model
- 关于网络数据传输大小端字节序的转换
- java JDK7安装后指定环境变量失败的原因
- Spring 各种Advice示例
- 推荐个软件:wxHexEditor,基于GPL协议,十六进制编辑器,支持存储设备底层读写!
- Debian系统常用命令(转)
- JavaScript实现复制功能
- python之 break语句和continue语句及PASS语句
- 黑马程序员-java基础(一)