spring MVC中关于model.addAttribute的使用方法【翻译】

关于model.addAttribute的使用方法

http://krams915.blogspot.com/2010/12/spring-3-mvc-using-modelattribute-in.html  (可能要 break the wall)

好像还有点难度的样子,先看懂这篇:

http://wenku.baidu.com/link?url=9PZuIW4KSl3_quLVmLs-rTjYJsHh3e35E6Nn5lJlNp3crol5bdKVeeaywiFt9Ub_XYW8UPM5CKrpvhK4Isc3QUhdYmt1q8rUHR_MhnR2VqG


http://blog.csdn.net/li_xiao_ming/article/details/8349115 这篇不是很清晰


简要翻译一下:(学习笔记,只保留要点)


【什么是ModelAttribute - MA】
MA在controller中的2个应用场景:


1. 放在 方法的参数中, MA映射了一个分配在特定的,方法参数中 的model.
---这就是控制器得到一个参考,找到object,获取从表单带来存在object里的值。
e.g.(see the processSubmit() method below)


2. 放在方法里,为model提供参考数据,
方法签名可以 包含同样的types,正如@RequestMapping(RM) annotation中预先声明的一样。
(see the populatePetTypes() method in the following example)


注意MA是在RM标记的处理方法之前执行。


要把objects暴露给jsp页面,@MA是个方便的东东。把object返回回controller也是方便。


【启用 Spring MVC,配3个xml文件】
To enable Spring MVC we need to add it in the web.xml


--web.xml
Take note of the URL pattern. When accessing any pages in our MVC application, the host name must be appended with


--spring-servlet.xml
This XML config declares a view resolver. All references to a JSP name in the controllers will map to a corresponding JSP in the /WEB-INF/jsp location.


--applicationContext.xml
By convention, we must declare an applicationContext.xml
applicationContext.xml
This XML config declares three beans to activate the Spring 3 MVC programming model.




  • 10
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值