Spring MVC学习笔记二

There are 3 ways for processing mapping from DispatcherServlet to Controller

BeanNameUrlHandlerMapping           map to url based on the name of Controller
SimpleUrlHandlerMapping                  map to url with the collection of properties which configurated in the context configuration files.
CommonsPathMapHandlerMapping   map to url with meta data.

they all implement the HandlerMapping interface.

Utilize multiple mapping processor

xml 代码
  1. < bean   id = "beanNameUrlMapping"   class = "org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" >   
  2.    < property   name = "Order" > < value > 1 </value > </property >   
  3. </bean >   
  4.   
  5. < bean   id = "simpleUrlMapping"   class = "org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >   
  6.    < property   name = "Order" > < value > 0</ value > </property >   
  7. </bean >   

The smaller the order value is, the higher priority will be get.

 

Spring has a hierarchical controller.
Controller<-AbstractController<-MultiActionController
                                                      <-BaseCommandController<-AbstractFormController<-SimpleFormController
                                                                                                                                                       <-AbstarctWizardFormController
                                                                                                         <-AbstractCommandController

ThrowawayController

BaseCommandController has validator property which can provide the validation functionality.

the Command Object service as VO, which is provide as a property in BaseCommandController.

AbstractWizardFormController is well suited in Corss Page Form situation.
Attention will pay when decide which page should be nevigate. The specified string used(_target1,_finsih,_cancel) come to rescue. P266 Spring in action for details.

There is a little different to process validation in corss page form. 
In this case, there are lots of properties. You should invode validatePage() to validate Command object each time when you jump aross the pages.

  
View Resolver
A View is a bean responsible for reder the result to the user.
How the render happen is depend on your view type.
The ViewResolver is a bridge between logic view name and view bean. 
Spring will consult ViewResolver when decide which view bean should be applied.
There are four types of ViewResolver.
    InternalResourceViewResolver interpret the logic name to a template file(Jsp,Velocity)
    BeanNameViewResolver              to a View bean configurated in the DispatcherServlet context configuration file.
    ResourceBundleViewResolver  to a View Object of a ResourceBundle
    XmlViewResolver                           interpret View Bean from a another xml(not main config files)

Please refer P278 Spring in Action for details.

Mutiple View Resolver can be configurated in the file, the same as the mutiple controller ,the ordr property used for set priortiy to mapping the logic name to view bean . 

Handler Exception

  1. < bean   id = "exceptionResolver"   class = "org.springframeowrok.web.servlet.handler.SimpleMappingExceptionResolver" >   
  2.    < property   name = "exceptionMappings" >   
  3.      < props >   
  4.        < prop   key = "java.lang.Exception" > friendlyError </ prop >   
  5.      </ props >   
  6.    </ property >   
  7. </ bean >   

 

xml 代码
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值