LoginSignup
1
0

【SpringBoot】LocalDate型のthymeleafでフォーマットして表示する

Posted at

はじめに

SpringBootでThymeleafを使用した日付の表示について、
フォーマット方法がいまいち理解できず行き詰まったのですがなんとか解決できましたので、その証跡を残します。

参考資料

実際のコード

HTMLファイル(日付入力用)

<p>日付を指定してください。</p>
<form th:action="@{/day}" method="get">
    <input type="date" name="date">
    <input type="submit" value="進む">
</form>

Controllerクラスの処理

    @GetMapping("/day")
    public String day(@RequestParam("date") LocalDate date, Model model) {
        this.date = date;
        model.addAttribute("date", date);
        return "date";
    }

HTMLファイル(日付表示用)

<h1 th:text="${#temporals.format(date, 'yyyy年MM月dd日')}"></h1>

ControllerクラスなどでフォーマットしなくてもHTMLファイルでフォーマットできることがわかりました。
とても便利なので多様していきたいと思います。

1
0
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
0