标签:work prefix 出错 request 复杂 cti entry val map
在springmvc的multicontroller当中,需要调用MethodNameResolver,包括:InternalPathMethodNameResolver、ParameterMethodNameResolver和PropertiesMethodNameResolver。其中,PropertiesMethodNameResolver的配置我觉得是相对复杂一点的。首先创造一个multicontroller:
<bean id="OneMulti" class="org.wcy.springmvcdemo.controller.OneMultiAction">
<property name="methodNameResolver" ref="Properties"/>
</bean>
然后设置UrlHandlerMapping:
1 <bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 2 <property name="alwaysUseFullPath" value="true"/> 3 <property name="urlDecode" value="true"></property> 4 <property name="mappings"> 5 <props> 6 <prop key="/mm/*">OneMulti</prop> 7 </props> 8 </property> 9 </bean>
最后配置PropertiesMethodNameResolver:
1 <bean id="Properties" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver"> 2 <property name="mappings"> 3 <map> 4 <entry key="/*/four.do"> 5 <value>four</value> 6 </entry> 7 </map> 8 </property>
而Controller的方法是:
1 public Map<String,Object> four(HttpServletRequest req,HttpServletResponse resp) 2 throws Exception 3 { 4 System.err.println("返回Map..."); 5 Map<String,Object> mm= new HashMap<String,Object>(); 6 mm.put("name","Lora"); 7 mm.put("addr","四川成都"); 8 return mm; 9 }
其中容易出问题的地方在于如果请求的地址是:http://localhost:8088/springmvcdemo/mm/four.do 而且又设置了prefix=/Jsps/;suffix=.jsp,那么通过请求four方法会转发到http://localhost:8088/springmvcdemo/Jsps/mm/four.jsp 也就说此时four.jsp需在mm文件夹下,否则会出错。
标签:work prefix 出错 request 复杂 cti entry val map
原文地址:http://www.cnblogs.com/eysonme/p/6740500.html