मेरे पास स्प्रिंगबूट ऐप है। वसंत प्रारंभकर्ता, एम्बेडेड टोमकैट, थाइमेलीफ टेम्पलेट इंजन, और एक निष्पादन योग्य जेएआर फ़ाइल के रूप में पैकेज का उपयोग करना।लोकलडेटाइम, ज़ोनडडेट टाइम और टाइमस्टैम्प
मेरे पास 2 गुण (initDate, endDate) के साथ एक डोमेन ऑब्जेक्ट है। मैं 2 कन्वर्टर्स MySQL DB
@Convert(converter = LocalDateTimeAttributeConverter.class)
private LocalDateTime initDate;
@Convert(converter = ZonedDateTimeAttributeConverter.class)
private ZonedDateTime endDate;
कनवर्टर 1 से निपटने के लिए बनाना चाहते हैं (ठीक है)
@Converter
public class LocalDateTimeAttributeConverter implements AttributeConverter<LocalDateTime, Timestamp> {
@Override
public Timestamp convertToDatabaseColumn(LocalDateTime localDateTime) {
return (localDateTime == null ? null : Timestamp.valueOf(localDateTime));
}
@Override
public LocalDateTime convertToEntityAttribute(Timestamp sqlTimestamp) {
return (sqlTimestamp == null ? null : sqlTimestamp.toLocalDateTime());
}
}
यह एक है कि मैं
@Converter
public class ZonedDateTimeAttributeConverter implements AttributeConverter<ZonedDateTime, Timestamp> {
@Override
public Timestamp convertToDatabaseColumn(ZonedDateTime zoneDateTime) {
return (zoneDateTime == null ? null : Timestamp.valueOf(zoneDateTime));
}
@Override
public ZonedDateTime convertToEntityAttribute(Timestamp sqlTimestamp) {
return (sqlTimestamp == null ? null : sqlTimestamp.toZonedDateTime());
}
}
लेकिन मैं बनाना चाहते है ऐसा नहीं हो सकता क्योंकि मेरे पास 2 त्रुटियां हैं:
The method valueOf(String) in the type Timestamp is not applicable for the arguments (ZonedDateTime)
और टाइमस्टैम्प विधि toZonedDateTime()
और अगर मैं ZonedDate के लिए किसी भी कनवर्टर नहीं जोड़ते हैं, जेपीए प्रकार varbinary(255)
वैसे आप किस समय क्षेत्र में चाहते हैं? (यह 'टिमस्टैम्प' को 'लोकलडेटाइम' में परिवर्तित करने से काफी टूटा हुआ लगता है, लेकिन वहां हम जाते हैं।) आप 'Timestamp.toInstant()' और 'Timestamp.from (Instant) 'के माध्यम से जाना चाह सकते हैं। –