intellij thymeleaf 命名空间未绑定

问题描述 投票:0回答:5

我正在使用 IntelliJ IDEA,但 thymeleaf 命名空间有问题。我创建了员工表单,并将其包含到其他模板中,因此我没有指定名称空间,但当我运行应用程序时它工作正常。有什么办法可以改变这种行为。我喜欢自动完成:-)

命名空间“th”未绑定示例:

intellij-idea thymeleaf
5个回答
27
投票

此外,如果您正在使用

Spring
,您应该使用以下内容:

<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
  <head>
     <title>Hello</title>
  </head>
  <body>
  </body>
</html>

区别在于

DOCTYPE
。 请参阅 Intellij Idea:Thymeleaf 命名空间未知


13
投票

要启用 Thymeleaf 的自动完成和 IDE 支持,请确保您已启用 Thymeleaf 插件。

File
->
Other Settings
->
Config Plugins
-> 勾选
Thymeleaf

还要在根标签中添加命名空间

<html .... xmlns:th="http://www.thymeleaf.org">


7
投票

在格式良好的文档中定义片段没有什么坏处(包括

html
head
body
等)。事实上,Thymeleaf 文档就是这样做的。

通过这种方式,您可以指定 thymeleaf 命名空间,以便获得自动完成功能,并且您还可以在浏览器中自行查看片段,这对于原型设计很有用。


3
投票

xmlns:sec="http://www.thymeleaf.org"
添加到 html 标签中对我很有帮助。所以现在看起来如下:

<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org"
      lang="en">
<head>

0
投票

如果您使用 Intellij IDEA,您还可以使用 JBLHtmlToThymeleaf 插件。使用此插件,您只需右键单击 HTML 文件并添加所需的命名空间即可。

操作步骤:(在IDE上)

File
->
Settings
->
Plugins
->
Marketplace
并搜索
JBLHtmlToThymeleaf

Install JBLHtmlToThymeleaf

安装完成后,右键单击所需的html文件,然后选择JBLHtmlToThymeleaf。

Right click the HTML file

该过程完成后,您将看到命名空间

xmlns: th = "http://www.thymeleaf.org"
已自动添加。

额外奖励:如果您想在 HTML 文件中使用 Spring Security,请不要忘记添加

xmlns: sec = "http://www.thymeleaf.org/extras/spring-security"

© www.soinside.com 2019 - 2024. All rights reserved.