首页 > 代码库 > Spring 4 官方文档学习(十一)Web MVC 框架之约定优于配置
Spring 4 官方文档学习(十一)Web MVC 框架之约定优于配置
当返回一个ModelAndView时,可以使用其addObject(Object obj)方法,此时的约定是:
- An
x.y.User
instance added will have the nameuser
generated. - An
x.y.Registration
instance added will have the nameregistration
generated. - An
x.y.Foo
instance added will have the namefoo
generated. - A
java.util.HashMap
instance added will have the namehashMap
generated. You probably want to be explicit about the name in this case becausehashMap
is less than intuitive. - Adding
null
will result in anIllegalArgumentException
being thrown. If the object (or objects) that you are adding could benull
, then you will also want to be explicit about the name.
还有:
- An
x.y.User[]
array with zero or morex.y.User
elements added will have the nameuserList
generated. - An
x.y.Foo[]
array with zero or morex.y.User
elements added will have the namefooList
generated. - A
java.util.ArrayList
with one or morex.y.User
elements added will have the nameuserList
generated. - A
java.util.HashSet
with one or morex.y.Foo
elements added will have the namefooList
generated. - An empty
java.util.ArrayList
will not be added at all (in effect, theaddObject(..)
call will essentially be a no-op).
官方文档链接:
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-coc
Spring 4 官方文档学习(十一)Web MVC 框架之约定优于配置
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。