티스토리 뷰

반응형

 

 

 



 

 

 

 

 

 

Thymeleaf 템플릿을 사용하게 되면

날짜 검색필터 같은 곳에 날짜값을 셋팅 해줘야 할때가 있다.

 

temporals를 사용하여 날짜를 셋팅 해본다.

 

#temporals.format(temporal, pattern)

 

temporal 에 날짜 개체를 기입하고 

pattern 을 정해주면 된다.

 

 

 

<input type="text" name="searchdate" th:value="${#temporals.format(#temporals.createNow(), 'yyyy-MM-dd')}"/>

 

이렇게 하면 오늘의 년월일 만 기입된다.

HH:mm:ss 추가해주면 시간 값까지 표기해줄 수 있다.

 

 

날짜검색필터 처럼 범위를 미리 셋팅해주고 싶으면 함수들을 이용해주면 된다.

 

 

<input type="text" name="searchSdate" th:value="${#temporals.format(#temporals.createNow().minusDays(30), 'yyyy-MM-dd')}"/>
~
<input type="text" name="searchEdate" th:value="${#temporals.format(#temporals.createNow(), 'yyyy-MM-dd')}"/>

 

 

 

 

 

 

 

 

 

더 많은 옵션은 아래 공식문서를 참고하시길 바랍니다.

 

Tutorial: Using Thymeleaf

1 Introducing Thymeleaf 1.1 What is Thymeleaf? Thymeleaf is a modern server-side Java template engine for both web and standalone environments, capable of processing HTML, XML, JavaScript, CSS and even plain text. The main goal of Thymeleaf is to provide a

www.thymeleaf.org

 

 

 

 

 



 

 

반응형
댓글
반응형
최근에 올라온 글
«   2024/10   »
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
Total
Today
Yesterday