码迷,mamicode.com
首页 > 数据库 > 详细

customerized convert from field type to DB field's type

时间:2015-04-24 14:09:15      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

@LastModifiedDate

@Convert(converter = LocalDateTime2TimestampConverter.class)

@Slf4j

public class LocalDateTime2TimestampConverter implements

AttributeConverter<LocalDateTime, Timestamp> {

 

@Override

public Timestamp convertToDatabaseColumn(LocalDateTime ld) {

return ld == null ? null : new Timestamp(ld.toDateTime().getMillis());

}

 

@Override

public LocalDateTime convertToEntityAttribute(Timestamp ts) {

if (ts != null) {

            try {

                return LocalDateTime.fromDateFields(ts);

            } catch (IllegalArgumentException ex) {

                log.warn("Can‘t convert {} to LocalDate", ts, ex);

            }

        }

        return null;

}

 

}

 

customerized convert from field type to DB field's type

标签:

原文地址:http://www.cnblogs.com/feika/p/4453173.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!