3
我的DTO字符串格式的日期字段。我的實體的日期爲LocalDate。目前我從地圖跳過它,然後手動顯式地設置它(字符串到日期,反之亦然)。Modelmapper將字符串轉換爲LocalDate
它可能自動進行轉換?我嘗試了Spring bean中的Converter,但它給了我很多編譯錯誤(類型Converter不接受參數,不覆蓋convert方法 - 也很多convert()的錯誤)。
@Bean
public ModelMapper studentModelMapper() {
....
Converter<String, LocalDate> toStringDate = new AbstractConverter<String, LocalDate>() {
protected String convert(String source) {
return source == null ? null : new LocalDate(source);
}
};
....
}
我對modelmapper不是很熟悉。任何幫助是極大的讚賞。
建議我嘗試用LocalDate for DTO,但問題是當我在前面發送此實體(REST調用)時,我得到以下JSON。
"dateOfBirth": {
"year": 1972,
"month": "JANUARY",
"monthValue": 1,
"dayOfMonth": 4,
"dayOfWeek": "TUESDAY",
"era": "CE",
"dayOfYear": 4,
"leapYear": true,
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
}
我的前端開發人員需要「YYYY-MM-DD」。
爲什麼不能在你的DTO使用LOCALDATE的? – Cyril