當我使用創建操作時,更新操作 th:value=*{name} 如何設定 th:field 值不相互沖突。
這是錯誤:
出現意外錯誤(型別=內部服務器錯誤,狀態=500)。執行處理器 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' 時出錯(模板:“designations” - 第 243 行,第 18 欄)
這是 html
<div class="modal-body">
<form th:action="@{/designations/create}" th:object="${newDesignation}" th:method="post">
<div class="form-group">
<label>Designation Name <span class="text-danger">*</span></label>
<input th:field="*{name}" class="form-control" type="text">
</div>
<div class="form-group">
<label>Department <span class="text-danger">*</span></label>
<select th:field="*{departmentName}" class="select">
<option th:each="i : ${departmentsList}" th:value="${i.name}" ></option>
</select>
</div>
<div class="submit-section">
<button class="btn btn-primary submit-btn">Submit</button>
</div>
</form>
</div>
<div class="modal-body">
<form th:action="@{/designations/update/{id}(id=${i.id})}" th:object="${designationToUpdate}" th:method="post">
<div class="form-group">
<label>Designation Name <span class="text-danger">*</span></label>
<input th:field="*{name}" class="form-control" type="text">
</div>
<div class="form-group">
<label>Department <span class="text-danger">*</span></label>
<select th:field="*{departmentName}" class="select">
<option th:each="i : ${departmentsList}" th:value="${i.name}" th:text="${i.name}"></option>
</select>
</div>
<div class="submit-section">
<button class="btn btn-primary submit-btn">Save</button>
</div>
</form>
</div>
uj5u.com熱心網友回復:
使用
所以(對我來說)它被證明,百里香葉使“沒有沖突”以不同甚至相同的(->串列屬性)呈現<input/>具有相同名稱的兩個欄位<form/>。
id另一方面,副本不是很好/ html 符合!(...不是用于 thymeleaf,而是用于客戶端使用。)請解決它,例如:
<input th:id="newName" ...
<!-- ... and -->
<input th:id="updateName" ...
使用 devtools,請確保:
spring.thymeleaf.cache=false
對于開發環境(僅限!;),這將增加觀察的可靠性。
...請按照堆疊跟蹤到最后!(我發現它們與其他模板框架完全相反:)。
我們可以通過(人為地引入一個錯字)來快速重現一些類似的錯誤資訊:
@Data
@AllArgsConstructor
class MyDto {
String namy; //!
}
-> 重建,重新加載 ->
2021-12-30 02:32:53.104 ERROR 20564 --- [nio-8080-exec-1] org.thymeleaf.TemplateEngine:
[THYMELEAF][http-nio-8080-exec-1] Exception processing template "test":
An error happened during template parsing (template: "class path resource [templates/test.html]")
#... like 1000 lines of stacktrace, referring to (first occurence of) *{name}, but then:
Caused by:
org.springframework.beans.NotReadablePropertyException:
Invalid property 'name' of bean class [com.example.thymeleaf.test.MyDto]:
Bean property 'name' is not readable or has an invalid getter method:
Does the return type of the getter match the parameter type of the setter?
#... few (hundred) more
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/399183.html
