Thymeleaf Template Parsing Error with LocalDateTime Formatting
krkarma777 opened this issue · comments
Description
We encountered a template parsing error when trying to format a java.time.LocalDateTime object using the #dates utility object in Thymeleaf. The application throws a TemplateInputException indicating that the format method cannot be found for LocalDateTime objects.
Error Message
org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "#dates.format(inquiry.inquiryDate, 'yyyy년 MM월 dd일')" (template: "users/myPage/active/customer_center_inquiries" - line 53, col 53)
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method format(java.time.LocalDateTime,java.lang.String) cannot be found on type org.thymeleaf.expression.Dates
Possible Cause
The issue seems to stem from the use of #dates.format with java.time.LocalDateTime, which is not supported by Thymeleaf's #dates utility object. Thymeleaf's #dates is primarily designed for java.util.Date objects.
We should utilize Thymeleaf's #temporals utility object, which supports the Java 8 Date and Time API (java.time), to format LocalDateTime objects. The code snippet causing the issue should be updated from:
<small th:text="${#dates.format(inquiry.inquiryDate, 'yyyy년 MM월 dd일')}">문의 날짜</small>
to
<small th:text="${#temporals.format(inquiry.inquiryDate, 'yyyy년 MM월 dd일')}">문의 날짜</small>