« | October 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | |
| 公告 |
戒除浮躁,读好书,交益友 |
Blog信息 |
blog名称:邢红瑞的blog 日志总数:523 评论数量:1142 留言数量:0 访问次数:9719921 建立时间:2004年12月20日 |

| |
[j2ee]tatan框架对于HandlerMapping映射的设计 原创空间, 软件技术, 电脑与网络
邢红瑞 发表于 2006/8/27 17:15:03 |
tatan框架是基于spring 1.x 系列的一个框架,其中扩展和修改spring的部分源码。spring mvc默认使用BeanNameUrlHandlerMapping, ApplicationContext中只有这样的一个映射策略。BeanNameUrlHandlerMapping有很多问题,首先是复杂的url映射不能处理,其次是controller必须是单体,但是spring mvc中有很多不是单体的,例如ThrowawayController。SimpleUrlHandlerMapping 是一个比较好的解决方案。其实两者是可以混用的,因为他们实现org.springframework.core.Ordered接口。例如<bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="order"> <value>0</value> </property> <property name="mappings"> <props> <prop key="/pop/aa.do"> AaController </prop> </props> </property> </bean><bean id="beanNameUrlMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"> <property name="order"> <value>1</value> </property> </bean>tatan使用自己实现HandlerMappingpublic class TatanHandlerMapping extends AbstractHandlerMappingimplements InitializingBean {public final static String DEFAULT_PARAM_NAME = "action";private String parameterName = DEFAULT_PARAM_NAME;private final Map<String, Object> paramMappings =new HashMap<String, Object>();public final void setParamMappings(Map<String, Object> paramMappings) {this.paramMappings.putAll(paramMappings);}public final void setParameterName(String parameterName) {this.parameterName = parameterName;}
protected Object getHandlerInternal(HttpServletRequest request)throws Exception {String parameterValue = request.getParameter(parameterName);return paramMappings.get(parameterValue);}public void afterPropertiesSet() throws Exception {Assert.hasText(parameterName,"参数不能为空");}}配置文件<beanclass="com.tatan.web.mapping.TatanHandlerMapping"><property name="defaultHandler" ref="defaultController" /><property name="parameterName" value="action" /><property name="paramMappings"><map><entry key="del" value-ref="delController" /><entry key="show" value-ref="showController" /></map></property></bean>使用时 http://tatan.org/springapp/app?action=del 就进入delController。 |
|
|