【发布时间】:2014-02-28 15:14:46
【问题描述】:
有没有办法在表达式中使用片段参数?
我想创建一个片段来显示具有相应绑定错误的字段,例如喜欢:
<div th:fragment="alert (field, fieldLabel)">
<label><span th:text="${fieldLabel}">Label:</span><input type="text" th:errorclass="field_error" th:field="*{field}"/></label>
<div th:if="${#fields.hasErrors(field)}"><span th:errors="*{field}">Some error</span></div>
</div>
获取片段:
<div th:replace=":: alert (field='firstName', fieldLabel='Firstname')">Field</div>
如何在 th:field 和 th:errors 属性的表达式中使用 field 参数? *{field} 至少不起作用。
【问题讨论】:
标签: spring spring-mvc thymeleaf