SpringMVC中如何将MultiActionController和CommandController结和使用

java 代码
 

   1. package com.betop.probe.controller.study; 
   2.  
   3. import java.util.HashMap; 
   4. import java.util.Map; 
   5.  
   6. import javax.servlet.http.HttpServletRequest; 
   7. import javax.servlet.http.HttpServletResponse; 
   8.  
   9. import org.springframework.validation.BindException; 
  10. import org.springframework.web.bind.ServletRequestDataBinder; 
  11. import org.springframework.web.servlet.ModelAndView; 
  12. import org.springframework.web.servlet.mvc.AbstractCommandController; 
  13.  
  14. import com.betop.probe.domain.MasterUser; 
  15.  
  16. public class UserMultiActionController3 extends AbstractCommandController{ 
  17.      
  18.     public UserMultiActionController3(){ 
  19.         this.setCommandClass(MasterUser.class); 
  20.     } 
  21.      
  22.     public ModelAndView demo1(HttpServletRequest req, HttpServletResponse resp)throws Exception { 
  23.          
  24.         Map model = new HashMap(); 
  25.         model.put("message", "这是MultiActioncontroller的第三种配置!"); 
  26.         return new ModelAndView("study/MultiActionControllerView3.vm", model); 
  27.     } 
  28.      
  29.     public ModelAndView demo2(HttpServletRequest req, HttpServletResponse resp)throws Exception{ 
  30.          
  31.          
  32.         MasterUser user = getCommand(req, resp); 
  33.          
  34.         Map model = new HashMap(); 
  35.          
  36.         model.put("user", user); 
  37.          
  38.         return new ModelAndView("study/result.vm", model); 
  39.         //return super.handleRequest(req, resp); 
  40.     } 
  41.      
  42.     private MasterUser getCommand(HttpServletRequest req, HttpServletResponse resp) throws Exception{ 
  43.          
  44.         MasterUser command = (MasterUser)getCommand(req); 
  45.         ServletRequestDataBinder binder = bindAndValidate(req, command); 
  46.         BindException errors = new BindException(binder.getBindingResult()); 
  47.          
  48.         return command; 
  49.     } 
  50.  
  51.     @Override 
  52.     protected ModelAndView handle(HttpServletRequest request, 
  53.             HttpServletResponse response, Object command, BindException errors) 
  54.             throws Exception { 
  55.         // TODO Auto-generated method stub 
  56.         return null; 
  57.     } 
  58.  
  59. } 

xml代码:

#       <bean id="testMulti3" class="com.betop.probe.controller.study.UserMultiActionController3"/> 
#  
# <bean id="proxyController" class="org.springframework.web.servlet.mvc.multiaction.MultiActionController"> 
#     <property name="methodNameResolver"> 
#         <ref bean="paraMethodResolver"/> 
#     </property> 
#  
#     <property name="delegate"> 
#         <ref bean="testMulti3"/> 
#     </property> 
# </bean> 
#  
# <bean id="SimpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
#        <property name="mappings"> 
#            <props> 
#         <prop key="/test/*.htm">proxyController</prop> 
#            </props> 
#        </property> 
#    </bean> 

<bean id="paraMethodResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
<property name="paramName">
<value>method</value>
</property>
</bean>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值