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;

}

}

上一篇:VS Code 开发asp.net core 遇到的坑


下一篇:[C#项目开源] MongoDB 可视化管理工具 (2011年10月-至今)