Qiita Conference 2025

Qiita史上最多!豪華12名のゲストが登壇

特別講演ゲスト(敬称略)

ymrl、成瀬允宣、鹿野壮、伊藤淳一、uhyo、徳丸浩、ミノ駆動、みのるん、桜庭洋之、tenntenn、けんちょん、こにふぁー

1
0

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 5 years have passed since last update.

Thymeleafで開発中にHTML内のth属性にwarningがついてしまう

Last updated at Posted at 2020-03-07

現象

eclipseやSTSでSpring boot + Thymeleafで開発しているとき、HTML内のth属性にwarningがついてウザい。
warning.PNG

環境

Spring Tool Suite 3

原因

htmlの属性にxmlns:th="http://www.thymeleaf.org"を書き忘れている。

sample.html
<!DOCTYPE html>
<html>
  <head>
    <title>Hello</title>
    <meta charset="utf-8" />
  </head>
  <body>
    <h1>Hello SpringBoot Sample</h1>
    <h1 th:text="${message}"></h1>
  </body>
</html>

対策

パターン1:HTML属性にxmlnsを書く

HTMLタグのxmlns属性を書いて、th属性があることをエディタに知らせる。

sample.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
  <head>
    <title>Hello</title>
    <meta charset="utf-8" />
  </head>
  <body>
    <h1>Hello SpringBoot Sample</h1>
    <h1 th:text="${message}"></h1>
  </body>
</html>

パターン2:th属性ではなく、data属性形式で書く

th属性ではなくdata属性の記述方式で書く
HTML5対応したい場合はこちら。個人的にはこちらを押したい。

sample.html
<!DOCTYPE html>
<html>
  <head>
    <title>Hello</title>
    <meta charset="utf-8" />
  </head>
  <body>
    <h1>Hello SpringBoot Sample</h1>
    <h1 data-th-text="${message}"></h1>
  </body>
</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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?