Teo*_*Teo 7 spring taglib tagx thymeleaf spring-boot
我用Spring MVC,JSP和Tyles创建了一个自定义标记库,所以我有几个.tagx文件.在新项目中,我决定尝试Spring Boot和Thymelaf,但我想保留我的自定义库......
如果可以使用thymleaf创建自定义标记库,那么你呢?或者,我是否可以以任何方式导入自定义标记库?
编辑
我添加一些代码以便更清楚.以下使用的标签是我的自定义标签.所以我把JSP包含在里面xmlns:form="urn:jsptagdir:/WEB-INF/tags/form"
<form:create id="fu_utente" modelAttribute="utente" path="/utente">
<div class="row">
<div class="col-md-12 text-center">
<h1 class="fa fa-user-plus" style="color:green;"><b>  Stai creando un nuovo utente di tipo: <var class="varFont"> ${utente.ruolo}</var></b></h1>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-4 col-md-offset-2">
<field:input field="nome" id="c_utente_nome" required="true"/>
</div>
<div class="col-xs-12 col-sm-12 col-md-4">
<field:input field="userName" id="c_utente_username" min="5" max="15" required="true"/>
</div>
<div class="col-xs-12 col-sm-12 col-md-8 col-md-offset-2">
<field:input field="email" id="c_Utente_email" required="true" validationRegex="^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$"/>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 col-md-offset-2">
<field:input field="nuovaPassword" id="c_utente_password" min="6" max="15" required="true" type="password"/>
</div>
<div class="col-xs-12 col-sm-12 col-md-4">
<field:input field="confermaNuovaPassword" id="c_utente_confirmPassword" required="true" type="password"/>
</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
此页面的结果是一个标准的HTML页面,其中包含一个表单,一些字段和标签以及一个提交按钮.
通过这种方式,我可以快速编写很多HTML代码.例如<label>..... </label><input....../>,我可以只<field:input......>使用国际化来代替每个字段的写入.
我想在Thymeleaf中拥有(我认为可能非常有用)同样的东西.
否则,如果您知道使用Thymeleaf的方法以避免节省代码和时间,请告诉我..
我使用以下内容作为一种解决方案/解决方法。目前我只创建了 2 个简单标签,我不确定这是否是实现更复杂标签的好方法。
输入标签
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<section th:fragment="input(name, value, type, required)" class="form-group" th:switch="${required}">
<label th:text="#{${name}}" th:for="${name}" class="control-label"></label>
<input th:case="true" th:type="${type}" th:id="${name}" th:name="${name}" th:value="${value}" class="form-control" required="required"/>
<input th:case="false" th:type="${type}" th:id="${name}" th:name="${name}" th:value="${value}" class="form-control"/>
</section>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
显示标签
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<section th:fragment="display(name, value)" class="form-group">
<label th:text="#{${name}}" th:for="${name}" class="control-label"></label>
<div class="box" th:id="${name}" th:text="${value}"></div>
</section>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
然后我使用这两个标签传递我想要的参数,例如:
<section th:replace="~{/tags/input :: input(username, *{username}, text, true)}"></section>
Run Code Online (Sandbox Code Playgroud)
和
<section th:replace="~{/tags/display :: display(nome, *{nome})}"></section>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1650 次 |
| 最近记录: |