SpringMVC 之 view-controller 与annotation-driven

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_43014205/article/details/85539228

在springmvc中,如果没有配置控制器,那么可以在springmvc的配置文件中添加 view-controller

分别有两个字段,  path表示跳转的链接     view-name表示跳转的目标页面

<mvc:view-controller path="testView" view-name="/result.jsp"/>

注意: 使用时还要在springmvc的配置文件中加上

<mvc:annotation-driven/>

否则Controller中的requestmapping将不能使用

原因:

spring在默认情况下会自动加载三个Bean:RequestMappingHandlerMapping、RequestMappingHandlerAdapter、ExceptionHandlerExceptionResolver。但是在配置了view-controller(形如mvc:~~~~~)后,RequestMappingHandlerMapping将不会被加载,因此得手动打开注释,<mvc:annotation-driven/>让其加载三个bean,使得requestmapping生效。

<mvc:annotation-driven/>并提供了:数据绑定支持、@NumberFormatanotation支持、@DateTimeFormat支持、@valid支持,读写xml的支持,读写json的支持

因此在一般开发中都会加上

猜你喜欢

转载自blog.csdn.net/weixin_43014205/article/details/85539228