Thymeleaf(switch, case)
2024. 6. 14. 19:12ㆍJSP+Spring Boot
변수 값에 따라 알맞은 case 진행.
<th:block th:switch="${num}">
<h4 th:case="100">AAAAAAAA</h4>
<h4 th:case="200">BBBBBBBB</h4>
<h4 th:case="300">CCCCCCCC</h4>
<h4 th:case="*">ZZZZZZZZ</h4>
th:case="*" : 작성한 경우의 값 의외 모두 선택을 한다는 의미. default 대신 사용
만약 Controller에서 num 값으로 가져오는 값이 없다면 default 값인 th:case="*"에
작성된 내용이 보여짐
** 삼항 연산자
- 타임 리프 속성(th:)에 삼항 연산자(조건식 ? true일 때 값 : false일 때 값) 작성 가능
<!-- ${} 기호는 사용되는 부분에만 작성 -->
<h4 th:text="${std.age == 30} ? '서른' : '서른 아님'">삼항 연산자</h4>
<!-- th로 시작하는 구문은 처음과 끝이 모두 이텔릭체+색상변경 돼야함, ""로 덮어야함
StudentDTO std = new StudentDTO("7890", "피카츄", 22);
피카츄의 나이를 22로 설정했기 때문에 서른 아님이 출력됨
-->
'JSP+Spring Boot' 카테고리의 다른 글
상품등록 폼 만들기(Java 파일)(insert) (0) | 2024.06.17 |
---|---|
Thymeleaf(inline, classappend), sequence (0) | 2024.06.14 |
Thymeleaf (if, unless) (0) | 2024.06.14 |
Thymeleaf(parameter, utext) (0) | 2024.06.14 |
Thymeleaf로 객체 값 얻어오기 (1) | 2024.06.14 |