mvc:view-controller和mvc:annotation-driven

2025-05-30 14:15:45

1、若希望直接响应通过SpringMVC渲染的页面,这些页面是没有控制层的。可以使用mvc:view-controller标签实现。<m即枢潋雳vc:view-controller path="/success" view-name="success"/>

mvc:view-controller和mvc:annotation-driven

2、在浏览器中直接访问地址:http://localhost:8080/SpringMVC/success这样就会跳转到success.jsp页面。

mvc:view-controller和mvc:annotation-driven

3、但是现在有一个问题,原来的地址访问路径现在不能访问了。

mvc:view-controller和mvc:annotation-driven

4、造成原有的访问路径不能访问是因为配置了mvc:view-controller,在实际开发中通常都需配置:<mvc:annotation-driven></mvc:annotation-driven>

mvc:view-controller和mvc:annotation-driven

5、配置了mvc:annotation-driven标签之后重新访问原来的地址:

mvc:view-controller和mvc:annotation-driven

6、现在以前的的地址和mvc:view-controller配置都能够正常访问。下一节课我们将讲解mvc:annotation-driven的作用。<?xml version=媪青怍牙"1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd"> <!-- 配置自动扫描的包 --> <context:component-scan base-package="com.gwolf.springmvc.handlers"> </context:component-scan> <!-- 配置视图解析器,如何把handler方法返回值解析为实际的物理视图 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/"></property> <property name="suffix" value=".jsp"></property> </bean> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/springmvc/helloworld"></mvc:mapping> <bean class="com.gwolf.springmvc.interceptors.SecondInterceptor"></bean> </mvc:interceptor> <bean class="com.gwolf.springmvc.interceptors.FirstInterceptor"></bean> </mvc:interceptors> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="i18n"></property> </bean> <mvc:view-controller path="/success" view-name="success"/> <mvc:annotation-driven></mvc:annotation-driven> </beans>

mvc:view-controller和mvc:annotation-driven
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢