commit
13ab8a152a
@ -0,0 +1,25 @@
|
|||||||
|
package com.baeldung.util;
|
||||||
|
|
||||||
|
import javax.persistence.AttributeConverter;
|
||||||
|
import javax.persistence.Converter;
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Converter(autoApply = true)
|
||||||
|
public class LocalDateConverter implements AttributeConverter<LocalDate, Date> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Date convertToDatabaseColumn(LocalDate localDate) {
|
||||||
|
return Optional.ofNullable(localDate)
|
||||||
|
.map(Date::valueOf)
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalDate convertToEntityAttribute(Date date) {
|
||||||
|
return Optional.ofNullable(date)
|
||||||
|
.map(Date::toLocalDate)
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user