关于转换器配置
<!-- 启动注解驱动 -->
<mvc:annotation-driven conversion-service="tc"/><!--启用自动扫描 -->
<context:component-scan base-package="com.wode.controller" />
<bean id="tc"
class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<list>
<bean class="com.wode.conventer.DateConventer" />
</list>
</property>
</bean>
<!-- ViewResolver视图解析器 用于将返回的ModelAndView对象进行分离 -->
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
编写一个普通类实现Converter类
public class DateConventer implements Converter<String, Date>{
@Override
public Date convert(String text) {
//日期转换器
Date date = null;
SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd");
try {
date = sm.parse(text);
System.out.println("转换成功");
System.out.println(date);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
}