我有一個HashMap,提供數據的某些文件:未指定Thymeleaf動態數據類型形式
Key | Value
----------------
Name | test1
Type | type1
...
行數和兩者鍵和值,都在第一串。
現在我想編輯這個動態數據。 Therfor我創造了這個模板:
<form action="#" th:action="@{/documents/{id}(id=${doc_id})}" th:object="${properties}" method="post">
<h1 th:text="${document_h1_text}">Documents</h1>
<table class="table table-striped">
<tr>
<th>Property</th>
<th>Value</th>
</tr>
<tr th:each="property : ${document_properties}">
<td th:text="${property.key}">Property</td>
<td>
<input name="${property.key}" th:value="${property.value}" />
</td>
</tr>
</table>
<button type="submit" class="btn btn-default">Submit</button>
</form>
的document_properties
關係到一個HashMap<String,String>
當我與
@RequestMapping(path = "documents/{doc_id}", method = RequestMethod.GET)
public String document(@PathVariable long doc_id, Model model) { ... }
得到這個Web服務能正常工作,現在我想編輯在此輸出前端並提交更改:
@PostMapping("documents/{doc_id}")
public String editDocument(@PathVariable long doc_id, @ModelAttribute HashMap<String, String> properties,Model model) { ... }
Unfort單擊HashMap properties
是空的,當我打電話通過點擊「提交」按鈕。你們有沒有人知道如何解決這個問題?僅供參考:我故意選擇不在這裏使用傳統的類綁定。原因是我想得到一個動態的解決方案,使用任意類。
非常感謝! – MS1