customerized convert from field type to DB field's type

@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;

}

 

}

 

posted @   samu  阅读(193)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示