Thymeleafで開発中にHTML内のth属性にwarningがついてしまう
現象
eclipseやSTSでSpring boot + Thymeleafで開発しているとき、HTML内のth属性にwarningがついてウザい。
環境
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>
Author And Source
この問題について(Thymeleafで開発中にHTML内のth属性にwarningがついてしまう), 我々は、より多くの情報をここで見つけました https://qiita.com/guchiinu/items/b1304eb437d405e6cf1f著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .