1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Thymeleafで関数の引数に変数を渡す方法

Last updated at Posted at 2020-03-27

謎にハマったのでメモ

環境

  • Thymeleaf 3.0.11
  • Spring Boot 2.2.5

実装方法

例)Thymeleaf内にて、Dateクラスにあるformatメソッドの引数に変数式を渡したい場合

HogeController.java
    model.addAttribute(mails);
    model.addAttribute(new Date());
index.html
  <tr th:each="mail : ${mails}">
    <td th:text="${mail.subject}">件名</td>
    <td th:text="${mail.category.}">通常</td>
    <td th:text="${Date.format(mail.sendDate)}">2020/03/20</td>
    <!-- ${Date.format(${mail.sendDate})} などでは構文エラーとなる-->
  </tr>
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?