Spring MVC学习笔记二 SpringMVCBeanServletvelocity
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
- < bean id = "beanNameUrlMapping" class = "org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" >
- < property name = "Order" > < value > 1 </value > </property >
- </bean >
- < bean id = "simpleUrlMapping" class = "org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >
- < property name = "Order" > < value > 0</ value > </property >
- </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
- < bean id = "exceptionResolver" class = "org.springframeowrok.web.servlet.handler.SimpleMappingExceptionResolver" >
- < property name = "exceptionMappings" >
- < props >
- < prop key = "java.lang.Exception" > friendlyError </ prop >
- </ props >
- </ property >
- </ bean >