admin管理员组文章数量:1794759
spring mvc 中Timestamp 日期的转换
今天碰到一个Timestamp类型的日期,javabean 用的是Timestamp类型的时间,因为要获取数据库的时分秒,数据库是date类型的时间 在页面传入action的处理过程中出现了时间转换错误 具体的解决办法如下 package com.safein.util; import java.sql.Timestamp; import org.apachemons.lang3.StringUtils; import org.springframework.core.convert.converter.Converter; /** * Timestamp日期类型转换 * @author julong * @date 2016-7-13 上午09:47:20 */ public class TimestampConverter implements Converter<String,Timestamp>{ @Override public Timestamp convert(String arg0) { // TODO Auto-generated method stub if(StringUtils.isNotEmpty(arg0.trim())){ Timestamp timestamp = Timestamp.valueOf(arg0); return timestamp; } return null; } } 在spring配置文件如下 <!-- 时间转换拦截器 --> <mvc:annotation-driven conversion-service="converterUtil" /> <bean id="converterUtil" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"> <property name="converters"> <list> <bean class="com.safein.util.TimestampConverter" /> </list> </property> </bean> 这样就能完美解决此问题了,特此一记
版权声明:本文标题:spring mvc 中Timestamp 日期的转换 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686616392a86610.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论