`
wutao8818
  • 浏览: 615745 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

ControllerClassNameHandlerMapping @Controller

阅读更多
这里也提到这个问题

http://forum.springsource.org/showthread.php?p=151750

Allow ControllerClassNameHandlerMapping and @Controller to work together

似乎在Spring mvc 2.5.4里面有一个 bug


就是当你实现一个controller 时候,使用 COC原则自动映射。无法映射到对应的默认方法 handleRequestInternal


这个问题在 spring 官方论坛的mvc版块里面也提到了这个问题。还是 appfuse Matt Raible 提交的。


具体的一个解决方式是 Keith Donald 提出的。看看他的配置文件就知道了。



Matt Raible 看了以后说


Thanks Keith - your webmvc-config.xml seems to contain the magic sauce that makes this work as expected.

引用

Keith Donald added a comment - 14/Apr/08 12:27 PM
In Matt's example the index method on HomeController would be mapped to the URL /home/index by the 2.5.3 convention, which I imagine isn't what he wants.
Just to provide more usage examples of this feature, here is an example in the Spring MVC + Web Flow reference application "booking-mvc". You can see the code on-line here: https://springframework.svn.sourceforge.net/svnroot/springframework/spring-webflow/trunk/spring-webflow-samples/booking-mvc

Specifically see:

@Controller code: https://springframework.svn.sourceforge.net/svnroot/springframework/spring-webflow/trunk/spring-webflow-samples/booking-mvc/src/main/java/org/springframework/webflow/samples/booking/HotelsController.java

Config:
https://springframework.svn.sourceforge.net/svnroot/springframework/spring-webflow/trunk/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/webmvc-config.xml

The URls mapped by convention are then:

/hotels/index
/hotels/search
/hotels/show
/hotels/deleteBooking

But no, /hotels doesn't mapped to to the index method by default... not in 2.5.3 anyway. Is this the convention you want? Perhaps we could employ a convention to map the root controller URL e.g. /home to a "home" method on the HomeController...






	<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

	<!-- Maps request paths to flows in the flowRegistry; e.g. a path of /hotels/booking looks for a flow with id "hotels/booking" -->
	<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
		<property name="order" value="0" />
		<property name="flowRegistry" ref="flowRegistry" />
	</bean>

	<!-- Maps request paths to @Controller classes; e.g. a path of /hotels looks for a controller named HotelsController -->
	<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
		<property name="order" value="1" />
		<property name="defaultHandler">
			<!-- If no @Controller match, map path to a view to render; e.g. the "/intro" path would map to the view named "intro" -->	
			<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
		</property>
	</bean>

	<!-- Resolves logical view names returned by Controllers to Tiles; a view name to resolve is treated as the name of a tiles definition -->
	<bean id="tilesViewResolver" class="org.springframework.js.ajax.AjaxUrlBasedViewResolver">
		<property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAjaxTilesView"/>
	</bean>

	<!-- Configures the Tiles layout system -->
	<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
		<property name="definitions">
			<list>
				<value>/WEB-INF/layouts/layouts.xml</value>
				<value>/WEB-INF/views.xml</value>
				<value>/WEB-INF/hotels/views.xml</value>
				<value>/WEB-INF/hotels/booking/views.xml</value>
			</list>
		</property>
	</bean>
	
	<!-- Dispatches requests mapped to POJO @Controllers implementations -->
	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

	<!-- Dispatches requests mapped to org.springframework.web.servlet.mvc.Controller implementations -->
	<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />

	<!-- Dispatches requests mapped to flows to FlowHandler implementations -->
	<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
		<property name="flowExecutor" ref="flowExecutor"/>
	</bean>

	<!-- Custom FlowHandler for the hotel booking flow -->
	<bean name="hotels/booking" class="org.springframework.webflow.samples.booking.BookingFlowHandler" />	
		
</beans>



提交到JIRA链接在这里
http://jira.springframework.org/browse/SPR-4129

下面2个spring mvc 相关的链接可以看看

http://blog.springsource.com/2007/11/14/annotated-web-mvc-controllers-in-spring-25/

http://code.google.com/p/nestorurquiza/wiki/SpringMVCTutorial
分享到:
评论

相关推荐

    controller-demo:如何使用Spring Controller的示范项目

    Spring 3.x Restfull示例 控制器类别名称매핑방법1번 ControllerClassNameHandlerMapping와Bean용해이용해이같 &lt; bean class = " one.contro

    使用Spring MVC构建Web应用程序1

    * ControllerClassNameHandlerMapping:通过使用控制器的类名作为URL基础将控制器映射到URL。 * DefaultAnnotationHandlerMapping:将请求映射给使用@RequestMapping注解的控制器和控制器方法。 * ...

    跟我学SpringMVC

    - **ControllerClassNameHandlerMapping**:通过URL映射到类名。 ##### 4. HandlerAdapter **HandlerAdapter**用于执行具体的Handler。SpringMVC提供了多种类型的Adapter,比如: - **...

    springMvc中文文档

    控制器类名-处理器映射ControllerClassNameHandlerMapping允许通过类名直接映射请求到处理器。 在控制器中设置Cache-Control、ETag和Last-Modified响应头可指导客户端如何缓存响应内容,以及如何在后续请求中使用...

    Spring_MVC_4.2.4_RELEASE_中文文档.pdf

    Spring MVC提供了“约定优于配置”的Web安全支持,可以通过配置`ControllerClassNameHandlerMapping`来实现基于控制器类名的映射。此外,还可以自定义异常解析器处理各种异常,包括业务异常和HTTP状态码的映射。 ...

    Spring MVC 4.2.4.RELEASE 中文文档

    WebApplicationContext 中特殊的 Bean 类型包括 HandlerMapping、HandlerAdapter、Controller 等,它们是框架用来处理请求的重要组件。 默认的 DispatcherServlet 配置涉及了 Spring 配置文件的设置,说明了如何...

    springmvc流程图以及配置解析

    2. ControllerClassNameHandlerMapping,根据controller名称进行对应,注意命名规则,地址栏上写最后的类名要全部小写,如果最后是controller,可以省略,也可以首字母不区分大小写。 3. SimpleUrlHandlerMappering...

    springmvcdemo

    3 URL Mapping: ControllerClassNameHandlerMapping 映射控制器 4 使用MultiActionController 5 所有service利用spring注入到controller中,利用注解 6 数据库连接串单独在properties文件配置 7 在spring中配置数据...

    Spring mvc 教程

    - **使用@Controller 注解定义一个控制器**:通过这个注解可以将类标记为一个控制器,Spring 会自动检测并将其纳入管理。 - **使用@RequestMapping 注解映射请求路径**:此注解用于指定控制器处理的具体 URL 路径...

    web mvc spring springmvc

    - `ControllerClassNameHandlerMapping`:根据请求URL自动推断处理器的类名。 - `RequestMappingHandlerMapping`:使用@RequestMapping注解自动映射。 ##### 3. HandlerAdapter(处理器适配器) - **定义**:...

    Spring中文帮助文档

    13.11.1. 对控制器的支持:ControllerClassNameHandlerMapping 13.11.2. 对模型的支持:ModelMap(ModelAndView) 13.11.3. 对视图的支持:RequestToViewNameTranslator 13.12. 基于注解的控制器配置 13.12.1. ...

    Spring API

    13.11.1. 对控制器的支持:ControllerClassNameHandlerMapping 13.11.2. 对模型的支持:ModelMap(ModelAndView) 13.11.3. 对视图的支持:RequestToViewNameTranslator 13.12. 基于注解的控制器配置 13.12.1. ...

    Spring-Reference_zh_CN(Spring中文参考手册)

    13.11.1. 对控制器的支持: ControllerClassNameHandlerMapping 13.11.2. 对模型的支持:ModelMap (ModelAndView) 13.11.3. 对视图的支持: RequestToViewNameTranslator 13.12. 其它资源 14. 集成视图技术 14.1. ...

    SPRING API 2.0.CHM

    ControllerClassNameHandlerMapping Conventions CookieGenerator CookieLocaleResolver CookieThemeResolver CosMailSenderImpl CosMultipartHttpServletRequest CosMultipartResolver CronTriggerBean ...

Global site tag (gtag.js) - Google Analytics