티스토리 뷰
반응형
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')}"/>
더 많은 옵션은 아래 공식문서를 참고하시길 바랍니다.
반응형
'Java > SpringBoot&Spring' 카테고리의 다른 글
[SpringBoot] 다중 Datasource, JPA+QueryDsl+Mybatis 사용 설정. (2) | 2023.11.03 |
---|---|
[SpringBoot JPA] 다중 DB 설정하기 (multi Datasource + 이기종 DB) (1) | 2023.10.19 |
[Gradle] Mybatis xml 파일, 타경로 빌드에 포함시키기 (feat.IntelliJ) : mapped statements collection does not contain value for 문제 해결 (0) | 2023.08.10 |
[SpringBoot] JavaMailSender 메일 보내기. (0) | 2023.08.03 |
[SpringBoot] 파일다운로드 컨트롤러 (feat.a href) (0) | 2023.07.26 |
댓글