| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
- 정처기실기요약
- HelloWorld출력
- 타임리프변수
- 타임리프기본객체
- 타임리프Unescape
- git
- 정보처리기사
- 스프링부트설정
- 타임리프유틸리티객체
- 정보처리기사실기
- 타임리프 표현식
- spring
- java
- mysql설치하기
- 이클립스없이cmd
- mybatis
- MySQL설치순서
- 정보처리기사실기요약
- ER모델
- 타임리프SpringEL
- 타임리프 특징
- mysql다운로드
- 타임리프날짜
- mysql
- 개체관계모델
- 타임리프URL
- cmd에서java파일실행
- 타임리프Escape
- thymeleaf
- 정처기실기
- Today
- Total
ye._.veloper
[ SpringMVC2 ] Thymeleaf (변수 - SpringEL) 본문
☁ 변수 표현식
· 타임리프에서 변수를 사용할 때는 변수 표현식을 사용한다.
- 변수 표현식 : ${...}
- 위의 변수 표현식에는 SpringEL이라는 스프링이 제공하는 표현식을 사용할 수 있다.
<ul>Object
<li>${user.username} = <span th:text="${user.username}"></span></li>
<li>${user['username']} = <span th:text="${user['username']}"></span></li>
<li>${user.getUsername()} = <span th:text="${user.getUsername()}"></span></li>
</ul>
<ul>List
<li>${users[0].username} = <span th:text="${users[0].username}"></span></li>
<li>${users[0]['username']} = <span th:text="${users[0]['username']}"></span></li>
<li>${users[0].getUsername()} = <span th:text="${users[0].getUsername()}"></span></li>
</ul>
<ul>Map
<li>${userMap['userA'].username} = <span th:text="${userMap['userA'].username}"></span></li>
<li>${userMap['userA']['username']} = <span th:text="${userMap['userA']['username']}"></span></li>
<li>${userMap['userA'].getUsername()} = <span th:text="${userMap['userA'].getUsername()}"></span></li>
</ul>
◽ Object
· user.username : user의 username을 프로퍼티 접근 ➡ user.getUsername()
· user['username'] : 위와 같음 ➡ user.getUsername()
· user.getUsername() : user의 getUsername()을 직접 호출
◽ List
· users[0].username : List에서 첫 번째 회원을 찾고 username 프로퍼티 접근 ➡ list.get(0).getUsername()
· users[0]['username'] : 위와 같음
· users[0].getUsername() : List에서 첫 번째 회원을 찾고 메서드 직접 호출
◽ Map
· userMap['userA'].username : Map에서 userA를 찾고, username 프로퍼티 접근 ➡ map.get("userA").getUsername()
· userMap['userA']['username'] : 위와 같음
· userMap['userA'].getUsername() : Map에서 userA를 찾고 메서드 직접 호출
☁ 지역 변수 선언
◽ th:with
· th:with를 사용하면 지역 변수를 선언해서 사용할 수 있다.
· 지역 변수는 선언한 태그 안에서만 사용할 수 있음
<h1>지역 변수 - (th:with)</h1>
<div th:with="first=${users[0]}">
<p>처음 사람의 이름은 <span th:text="${first.username}"></span></p>
</div>
'Spring' 카테고리의 다른 글
| [ SpringBoot ] @SpringBootApplication / Bean 등록 (0) | 2023.07.09 |
|---|---|
| [ SpringMVC2 ] Thymeleaf (타임리프 기본, 유틸리티 객체와 날짜, URL 링크) (0) | 2023.05.02 |
| [ SpringMVC2 ] Thymeleaf 정의 | 기본 기능 (0) | 2023.04.23 |
| [ IntelliJ ] Unmapped Spring configuration file : 파일명 (0) | 2023.02.14 |
| [ Spring Boot ] 1. 게시판 만들기 - 초기 개발 설정하기 (0) | 2023.02.11 |