νλ‘μ νΈ μ€ ToDo 리μ€νΈλ₯Ό λ΄λΉνκ² λμλλ° ENUM (-> DOING κ³Ό DONE) ννλ‘ μ μ₯ν type μ λ°λΌ DOING μ΄λ©΄ 체ν¬λ°μ€κ° ν΄μ λκ³ DONE μ΄λ©΄ 체ν¬λ°μ€κ° νμ±νλλ κ³Όμ μ νμ리νλ₯Ό νμ©νμ¬ κ΅¬νν΄λ³΄κ³ μ νλ€.
<li class="list-group-item d-flex align-items-center border-0 mb-2 rounded"
style="background-color: #f4f6f7;" th:each="todo : ${toDoList}">
<input class="form-check-input me-2" type="checkbox" value="" aria-label="..."/>
<s th:text="${todo.content}"></s>
<li>
μΌλ¨ li νκ·Έμμ th:each λ¬Έμ νμ©νμ¬ ν μ΄λΈμ μλ λͺ¨λ λ°μ΄ν°λ€μ νλμ© κ°μ Έμ€λ κ² κΉμ§λ μ±κ³΅νλ€.


λμ 1 : th:if μ th:unless νμ©
μΌλ¨ todo.type μΌλ‘ μνκ°μ λμ΄μ€κ³ νμ 리νμ if & else λ¬Έμ μ΄μ©ν΄μ ν΄κ²°ν΄λ³΄κ³ μ νλ€.
<li class="list-group-item d-flex align-items-center border-0 mb-2 rounded"
style="background-color: #f4f6f7;" th:each="todo : ${toDoList}">
<input class="form-check-input me-2" type="checkbox"
th:if="${todo.type == 'DOING'}" value="" aria-label="..."/>
<input class="form-check-input me-2" type="checkbox"
th:unless="${todo.type == 'DOING'}" value="" aria-label="..." checked/>
<s th:text="${todo.content}"></s>
<li>
-> μ€ν¨
=> th:if λ¬Έμ μ¬μ©ν΄μΌνλ κ²μ λ§λ€κ³ μκ°, κ·Έλ λ€λ©΄ todo.type == 'DOING' μμ λ¬Έμ κ° λ°μνκ² μλκΉ? νλ μκ°.
=> μ€μ λ‘ νλ©΄μ todo.type λ§ μ°μ΄λ³΄μμ λ μ μμ μΌλ‘ 'DOING' κ³Ό 'DONE' μ΄ λμλ€. κ·Έλ¬λ©΄ λΉκ΅νλ κ³Όμ μμμ λ¬Έμ λΌκ³ μκ°νλ€. type μ νμ μ ENUM μ΄μ§λ§ λΉκ΅νλ κ²μ λ¬Έμμ΄μ΄λ.
λμ 2 : Enum μ name() νμ©
ENUM μ λν΄ μ΄ν΄λ³΄λ μ€ μλμ κ°μ λ§€μλκ° μλ κ²μ μμλ€.
public final String name()
ENUM μ λ΄μ©μ λ¬Έμμ΄λ‘ λ°νν΄μ£Όλ λ§€μλμ΄λ€. μ λ§€μλλ₯Ό μ μ© μμΌμ μλμ κ°μ΄ μμ±ν΄λ³΄μλ€.
th:if="${todo.type.name() == 'DOING'}"
-> μ±κ³΅

'Spring Boot πΏ' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
| (Spring) url νλΌλ―Έν° κ°μ μΈμ μ μ μ₯ (0) | 2022.10.07 |
|---|---|
| (Spring) Spring Boot DevTools μ¬μ©λ² (μλ² μ¬μ€ν μμ΄ μ½λ μμ νμΈ) (0) | 2022.10.06 |
| (Spring) @PreAuthorize μ¬μ©λ² (0) | 2022.08.22 |
| (Spring) λΉλκΈ° μ²λ¦¬ ꡬν 1 (0) | 2022.08.21 |
| (Spring) JPA μ¬μ©μ Truncate μλ¬ ν΄κ²° (0) | 2022.08.11 |