SSR 방식의 프로젝트중 Enum 값에 따라서 다른 text 가 출력될 필요가 있었다.
Enum 객체
package com.baeker.baeker.myStudy;
public enum StudyStatus {
MEMBER, PENDING, INVITING
}
<h3 th:if="${myStudy.status eq 'PENDING'"
th:text="|${myStudy.study.name}에 가입 신청|"
class="font-bold text-lg">
</h3>
<h3 th:if="${myStudy.status eq 'INVITING'"
th:text="|${myStudy.study.name}에서 초대|"
class="font-bold text-lg">
</h3>
th:each
문에 의해 반복된 하나의 Index 이다.${@객체명}
이 방법을 사용하면 타임리프에서 Bean 으로 등록된 java 객체로 바로 접근이 가능하다는 걸 알고있었다.@Component
를 선언하니 아래와 같은 문제가 발생했다.***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.baeker.baeker.myStudy.StudyStatus required a bean of type 'java.lang.String' that could not be found.
${T(com 부터 객체까지의 경로)}
th:object
를 사용하면 더 편리하게 사용이 가능하다.<h3 th:if="${myStudy.status eq T(com.baeker.baeker.myStudy.StudyStatus).PENDING}"
th:text="|${myStudy.study.name}에 가입 신청|"
class="font-bold text-lg"></h3>
<h3 th:if="${myStudy.status eq T(com.baeker.baeker.myStudy.StudyStatus).INVITING}"
th:text="|${myStudy.study.name}에서 초대|"
class="font-bold text-lg"></h3>