스프링부트 Thymeleaf에서는 변수를 쓸 때 ${변수} 이런 식으로 쓸 수 있다.
내가 오늘 개발을 하다가

<td th:text="${product.price}"></td>

이런 코드를 작성했다.
그런데 "800"이 아니라 "800원"으로 보이면 좋을 것 같아서

<td th:text="${product.price}원"></td>

코드를 이렇게 수정했다.

그랬더니 이런 에러가 났다.

ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/파일이름.html]")] with root cause
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "${product.price}원"


변수를 쓸 때 ${}를 쓰는거라고 해서 그냥 문자열은 ${} 바깥쪽에 적어줬는데 이렇게 하면 안 되는 것이었다.
아래의 코드처럼 작성해야 한다.

<td th:text="|${product.price}원|"></td>

이렇게 큰 따옴표 안쪽에 |을 넣어주었더니 에러 없이 잘 돌아갔다.

출처: https://velog.io/@susu1991/Thymeleaf#%EB%A6%AC%ED%84%B0%EB%9F%B4

+ Recent posts