[Spring Thymeleaf] Enum 필드 Switch-Case 사용법

dondonee·2023년 10월 28일
0
<p>
우선순위 : <th:block th:switch="${#strings.toString(task.priority)}">
            <span th:case="HIGH">높음</span>
            <span th:case="MEDIUM">보통</span>
            <span th:case="LOW">낮음</span>
        </th:block>
</p>
  • 문제: 필드가 String 타입인 경우에는 그냥 th:switch=${task.string}라고 하면 switch-case가 동작하는데, 필드가 Enum 타입인 경우 th:switch 상태에서 String 타입이 아닌것 같다. th:text=”${task.priority}”가 “HIGH”로 출력되어도 th:case=”HIGH”에서는 동일하게 취급이 안된다.
  • 해결: th:switch에서 toString()을 통해 String 타입으로 바꿔주니 해결되었다.
  • 🔗 도움 받은 블로그

0개의 댓글