본 게시물은 스스로의 공부를 위한 글입니다.
틀린 내용이 있을 수 있습니다.
타임리프 유틸리티 객체들
#message
: 메시지, 국제화 처리
#uris
: URI 이스케이프 지원
#dates
: java.util.Date 서식 지원
#calendars
: java.util.Calendar 서식 지원
#temporals
: 자바8 날짜 서식 지원
#numbers
: 숫자 서식 지원
#strings
: 문자 관련 편의 기능
#objects
: 객체 관련 기능 제공
#bools
: boolean 관련 기능 제공
#arrays
: 배열 관련 기능 제공
#lists
, #sets
, #maps
: 컬렉션 관련 기능 제공
#ids
: 아이디 처리 관련 기능 제공, 뒤에서 설명
공식 문서: https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#expression-utilityobjects
사용 예시: https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#appendix-b-expressionutility-objects
나중에 필요할 때 찾아서 사용하자
cf) 🎈자바8 날짜 포맷팅:
<span th:text="${#temporals.format(localDateTime, 'yyyy-MM-dd HH:mm:ss')}"></span>
타임리프에서 URL을 생성할 때는 @{...}
문법을 사용하면 된다.
단순한 URL
@{/hello}
-> /hello
쿼리 파라미터
@{/hello(param1=${param1}, param2=${param2})}
/hello?param1=data1¶m2=data2
경로 변수
@{/hello/{param1}/{param2}(param1=${param1}, param2=${param2})}
/hello/data1/data2
경로 변수 + 쿼리 파라미터
@{/hello/{param1}(param1=${param1}, param2=${param2})}
/hello/data1?param2=data2
cf) 🎈상대경로, 절대경로, 프로토콜 기준을 표현할 수도 있다
/hello
: 절대 경로hello
: 상대 경로리터럴은 소스 코드상에 고정된 값을 말하는 용어이다.
타임리프는 다음과 같은 리터럴이 있다
'hello'
10
true
, false
null
문자에 공백이 있다면 작은 따음표(')로 감싸야 한다.
너무 귀찮다.. 리터럴 대체(Literal substitutions) 문법을 사용하자
| |
내에 있는 문자가 그대로 변환된다.<span th:text="|hello ${data}|">
인프런의 '스프링 MVC 2편(김영한)'을 스스로 정리한 글입니다.
자세한 내용은 해당 강의를 참고해주세요.