LoginSignup
6
6

More than 5 years have passed since last update.

thymeleaf : TemplateInputException でハマった件

Posted at

th:replace を使いたいと思って、ちょっとだけハマりました。

失敗したやり方

/templates/admin/input.html で利用するために、以下の部品テンプレートを作成した。

/templates/components/buhin.html
<body>
    <input type="hidden" name="mode" th:value="${mode}" />
</body>

本体のテンプレートファイルが、

/templates/admin/input.html
<div th:replace="${components/buhin}"></div>

↓↓↓↓↓
以下のエラーが出た

org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/admin/input.html]")
    at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241)
    at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100)
    at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666)
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098)
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072)
    at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:354)
    at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:187)
(中略)
Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "components/buhin" (template: "admin/input" - line 30, col 7)
    at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393)
    at org.attoparser.MarkupParser.parse(MarkupParser.java:257)
    at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230)
    ... 86 common frames omitted
(後略)

修正した内容

/templates/components/buhin.html
<body>
    <div th:replace="components/buhin"></div>
</body>

これでOKだった。

6
6
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
6
6