Spring 4 官方文档学习(十一)Web MVC 框架之约定优于配置
当返回一个ModelAndView时,可以使用其addObject(Object obj)方法,此时的约定是:
- An
x.y.Userinstance added will have the nameusergenerated. - An
x.y.Registrationinstance added will have the nameregistrationgenerated. - An
x.y.Fooinstance added will have the namefoogenerated. - A
java.util.HashMapinstance added will have the namehashMapgenerated. You probably want to be explicit about the name in this case becausehashMapis less than intuitive. - Adding
nullwill result in anIllegalArgumentExceptionbeing 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.Userelements added will have the nameuserListgenerated. - An
x.y.Foo[]array with zero or morex.y.Userelements added will have the namefooListgenerated. - A
java.util.ArrayListwith one or morex.y.Userelements added will have the nameuserListgenerated. - A
java.util.HashSetwith one or morex.y.Fooelements added will have the namefooListgenerated. - An empty
java.util.ArrayListwill 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
浙公网安备 33010602011771号