Skip to content

Commit

Permalink
Fix: YearMonth 값 String으로 변환
Browse files Browse the repository at this point in the history
  • Loading branch information
Hawardshin committed Sep 8, 2024
1 parent 514fe09 commit ae56665
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package mejai.mejaigg.global.jpa;

import java.time.YearMonth;
import java.time.format.DateTimeFormatter;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

@Converter(autoApply = true)
public class YearMonthDateAttributeConverter implements
AttributeConverter<YearMonth, String> {
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM");

@Override
public String convertToDatabaseColumn(
YearMonth attribute) {
return attribute != null ? attribute.format(FORMATTER) : null;
}

@Override
public YearMonth convertToEntityAttribute(
String dbData) {
return dbData != null ? YearMonth.parse(dbData, FORMATTER) : null;
}
}

0 comments on commit ae56665

Please sign in to comment.