0
當
我試圖找到一個乾淨的解決方案,以下反模式與我 Thymeleaf /瓦應用:模式,以避免重複內容使用Thymeleaf和Apache瓷磚
我有2種形式(位於兩個不同現在的模板),它們與完全相同,但是對於指向不同URL的012行動屬性:。
第一種形式:
<form th:object="${advertisementInfo}" th:action="@{/advertisement/family/new}" method="post" class="form-horizontal">
<div th:if="${#fields.hasErrors('*')}" class="alert alert-danger form-group">
<ul>
<li th:each="err : ${#fields.errors('*')}" th:text="${err}"></li>
</ul>
</div>
<input type="hidden" th:field="*{advertisement.id}"/>
<div th:class="${#fields.hasErrors('advertisement.needs')}? 'form-group error':'form-group'">
<label class="control-label col-lg-3" for="needs" th:text="#{advertisement.family.form.needs}">Needs</label>
<div class="col-lg-6">
<select multiple="multiple" th:field="*{advertisement.needs}" class="form-control">
<option th:each="need: ${needs}" th:value="${need}" th:text="#{${'domain.enum.need.' + need}}"></option>
</select>
</div>
</div>
第二種形式是相同的,但對於日:action屬性是如下:th:action="@{/advertisement/family/edit}"
我想過很多方法可以解決我的這個反模式:
- 有兩種不同的形式,包括(identica l)用
tiles:include
表格內容。 - 尋找一種方法來以某種方式將
th:action
的值作爲變量。
不過,我會很感激,如果有人誰遇到了同樣的問題,可以建議我最好的做法...
我遵循你的建議,並最終使用參數化。非常感謝! – balteo