[@controller]4 详解@modelattribute

[@controller]4 详解@modelattribute

ID:11596893

大小:21.03 KB

页数:4页

时间:2018-07-12

[@controller]4 详解@modelattribute_第1页
[@controller]4 详解@modelattribute_第2页
[@controller]4 详解@modelattribute_第3页
[@controller]4 详解@modelattribute_第4页
资源描述:

《[@controller]4 详解@modelattribute》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、A、@ModelAttributeAnnotationthatbindsamethodparameterormethodreturnvaluetoanamedmodelattribute,exposedtoawebview.SupportedforRequestMappingannotatedhandlerclasses.在被@RequestMapping注释的处理器类中,这个注释可以绑定一个方法参数或绑定一个方法的返回值到一个命名的模型属性,提供给一个视图。Canbeusedtoexposecommandobjectstoawebview,usingspecificattribu

2、tenames,throughannotatingcorrespondingparametersofaRequestMappingannotatedhandlermethod).可以用于把一个command对象提供给web视图,使用指定的属性名称,在被@RequestMapping注释的处理器方法中注释相关参数。CanalsobeusedtoexposereferencedatatoawebviewthroughannotatingaccessormethodsinacontrollerclasswhichisbasedonRequestMappingannotatedhandle

3、rmethods,withsuchaccessormethodsallowedtohaveanyargumentsthatRequestMappingsupportsforhandlermethods,returningthemodelattributevaluetoexpose.可以用于提供数据给一个web视图,通过注释处理器方法,这个方法允许有任何参数,返回的模型属性值被提供。A.1、@ModelAttribute的属性valueThenameofthemodelattributetobindto.绑定的模型属性的名称。Thedefaultmodelattributenamei

4、sinferredfromthedeclaredattributetype(i.e.themethodparametertypeormethodreturntype),basedonthenon-qualifiedclassname:e.g."orderAddress"forclass"mypackage.OrderAddress",or"orderAddressList"for"List".默认的模型属性名称自动判断声明的属性类型(如,方法参数类型或方法返回类型)。如这个值是orderAddress,就对于当前包.OrderAddr

5、ess。B、@ModelAttribute注释一个方法An@ModelAttributeonamethodindicatesthepurposeofthatmethodistoaddoneormoremodelattributes.Suchmethodssupportthesameargumenttypesas@RequestMappingmethodsbutcannotbemappeddirectlytorequests.Instead@ModelAttributemethodsinacontrollerareinvokedbefore@RequestMappingmethods

6、,withinthesamecontroller.被@ModelAttribute注释的方法表示这个方法的目的是增加一个或多个模型(model)属性。这个方法和被@RequestMapping注释的方法一样也支持@RequestParam参数,但是它不能直接被请求映射。实际上,控制器中的@ModelAttribute方法是在同一控制器中的@RequestMapping方法被调用之前调用的。@ModelAttributemethodsareusedtopopulatethemodelwithcommonlyneededattributesforexampletofilladrop-d

7、ownwithstatesorwithpettypes,ortoretrieveacommandobjectlikeAccountinordertouseittorepresentthedataonanHTMLform.被@ModelAttribute注释的方法用于填充model属性,例如,为下拉菜单填充内容,或检索一个command对象(如,Account),用它来表示一个HTML表单中的数据。Acontrollercanhaveanynumberof@ModelA

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。