本站首页    管理页面    写新日志    退出


«October 2025»
1234
567891011
12131415161718
19202122232425
262728293031


公告

戒除浮躁,读好书,交益友


我的分类(专题)

日志更新

最新评论

留言板

链接

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。


阅读全文(2654) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 1.149 second(s), page refreshed 144815689 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号