【发布时间】:2018-04-06 11:40:59
【问题描述】:
我用 Spring MVC、JSP 和 Tyles 创建了一个自定义标签库,所以我有几个 .tagx 文件。
在新项目中,我决定尝试 Spring Boot 和 Thymelaf,但我想保留我的自定义库...
那么您是否可以使用 thymleaf 创建自定义标签库?或者我是否可以以任何方式导入我的自定义标签库?
编辑
为了更清楚,我添加了一些代码。以下使用的标签是我的自定义标签。所以我用xmlns:form="urn:jsptagdir:/WEB-INF/tags/form"包含在JSP中
<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>
这个页面的结果是一个标准的 HTML 页面,里面有一个表单、一些字段和标签以及一个提交按钮。..
这样我可以快速写出很多html代码。例如,不用为每个字段写<label>..... </label><input....../>,我也可以使用国际化只写<field:input......>。
我希望在 Thymeleaf 中拥有(并且我认为可能非常有用)同样的东西。
否则,如果您知道使用 Thymeleaf 避免节省代码和时间的方法,请告诉我..
【问题讨论】:
标签: spring spring-boot thymeleaf taglib tagx