如果我在spring-boot项目中添加一些自定义标签,是否可以在基于百里香叶的文件中使用它们?例如,如果我在TLD文件中定义了此标签(放在目录/ src / main / resources / static中):
<tag>
<name>Input</name>
<tag-class>org.store.custom.taglib.form_control.InputTag</tag-class>
</tag>
我可以在我的视图中这样使用它吗:
<p th:case="'Input'"><f:Input/></p>
任何人都知道这是否可能吗?
UPDATE
我尝试过,但是在运行应用程序时,自定义标签未处理为相应的标签:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="/form.tld" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>cadastro</title>
</head>
<body>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">cadastro</h3>
</div>
<div class="panel-body">
<f:form th:attr="action=@{/__${command.getClass().getSimpleName()}__/cadastra}">
<div th:each="item : ${command['class'].declaredFields}">
<div th:each="item2 : ${item.declaredAnnotations}">
<div th:switch="${item2.annotationType().simpleName}" th:with="index=${itemStat.index}">
<p th:case="'Checkbox'"><f:Checkbox/></p>
<p th:case="'DataList'"><f:DataList/></p>
<p th:case="'Input'"><f:Input/></p>
<p th:case="'Radiobutton'"><f:Radiobutton/></p>
<p th:case="'Select'"><f:Select/></p>
<p th:case="'Textarea'"><f:Textarea/></p>
</div>
</div>
</div>
</f:form>
</div>
</div>
</body>
</html>
没有Thymeleaf的基本原则是不应存在任何外来标签。 (仅标准html)。所有动态内容都是通过自定义属性添加的。
您可以使用这种方式
<input th:attr="your string message ='\'' + #{yourObject.meesage}" + '\''"/>
更多示例:https://attacomsian.com/blog/thymeleaf-custom-html-attributes