日期转换器
程序员文章站
2022-05-19 15:31:56
...
1、utils方法
**
* @author 捷轻
* @Company com.jieqing
* @Class
* @Desc字符串转日期的转换器必须实现Converter接口
*/
public class StringToDataConverter implements Converter<String, Date> {
@Override
public Date convert(String s) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date parse = null;
try {
parse = sdf.parse(s);
} catch (ParseException e) {
e.printStackTrace();
}
return parse;
}
}
2、在spring中进行配置
<!--配置转换器,在开启注解中引用才能生效-->
<bean id="conversionServiceFactoryBean" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<set>
<bean class="cn.itcast.utils.StringToDataConverter"></bean>
</set>
</property>
</bean>
<!-- 开启SpringMVC框架注解的支持 -->
<mvc:annotation-driven conversion-service="conversionServiceFactoryBean"/>
上一篇: MySQL主从同步加速 Transfer-- FAQ
下一篇: java map转xml