Thymeleaf ๋ฌธ๋ฒ• ์ •๋ฆฌ

๐Ÿ“Œ LocalDateTime → 'YYYY-mm-dd'

<td class="tx_cnt" th:if="${list?.regDate != null}"
 th:text="${#temporals.format(list.regDate, 'yyyy-MM-dd')}"></td>
  • LocalDateTime/LocalDate ๋Š” #temporals ์‚ฌ์šฉํ•ด์„œ ๋ณ€ํ™˜ ๊ฐ€๋Šฅ.

๐Ÿ“Œ String → LocalDateTime → ๋‚ ์งœ ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜

<td class="tx_cnt fs16" id="cert_date"
    th:if="${result?.pubDate != null}"
    th:text="${#temporals.createDate(result.pubDate, 'yyyyMMdd')}">
  • temporals.createDate ๋กœ LocalDate๋กœ ๋ณ€ํ™˜ํ•œ ๋’ค yyyy-MM-dd String ๋‚ ์งœ๋กœ ๋ณ€ํ™˜.

๐Ÿ“Œ NULL ์ฒ˜๋ฆฌ

How to handle null values in Thymeleaf

<input type="hidden" id="cert_certId" th:value="**${result?.certId}"** name="certId">
  • ? ์‚ฌ์šฉํ•ด์„œ null์ฒ˜๋ฆฌ
  • StringUtil ์‚ฌ์šฉํ•˜๊ธฐ
    • isEmpty
    <td class="tx_cnt" 
        th:if="${not #strings.isEmpty(list?.applyStartDate)}"
        th:text="${#temporals.createDate(list?.applyStartDate, 'yyyyMMdd')}">

? ์‚ฌ์šฉํ•ด์„œ null ์ฒ˜๋ฆฌ ํ•ด์ค€๋‹ค.