1.使用ConversionService
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="https://www.springframework.org/schema/beans"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="https://www.springframework.org/schema/aop"
xmlns:context="https://www.springframework.org/schema/context"
xmlns:mvc="https://www.springframework.org/schema/mvc"
xmlns:p="https://www.springframework.org/schema/p"
xsi:schemaLocation="https://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
https://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
https://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 配置处理器Handle,映射为“/hello”的请求 -->
<!-- <bean name="/hello" class="com.springmvc.controller.HelloController" /> -->
<mvc:annotation-driven conversion-service="conversionService"/>
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<list>
<bean class="com.springmvc.converter.StringToDateConverter" p:datePattern="yyyy-MM-dd"></bean>
</list>
</property>
</bean>
<!-- 配置自动扫描的基包 -->
<context:component-scan base-package="com.springmvc"/>
<!-- 配置视图解析器,将控制器方法返回的逻辑视图解析为物理视图 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<!-- <property name="prefix" value="/ch06/"></property> -->
<!-- <property name="prefix" value="/ch07/" /> -->
<property name="prefix" value="/ch09/" />
<property name="suffix" value=".jsp"></property>
</bean>
<!-- 直接页面转发 -->
<mvc:view-controller path="success" view-name="success"/>
<mvc:view-controller path="index" view-name="index"/>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver">
<property name="order" value="50"></property>
</bean>
<mvc:default-servlet-handler/>
</beans>
<?xml versio