【发布时间】:2016-11-14 13:38:43
【问题描述】:
我有一个 HashMap,为某些文档提供数据:
Key | Value
----------------
Name | test1
Type | type1
...
没有指定行数,键和值一开始都是字符串。
现在我想编辑这个动态数据。因此我创建了这个模板:
<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) { ... }
现在我想在前端编辑这个输出并提交更改:
@PostMapping("documents/{doc_id}")
public String editDocument(@PathVariable long doc_id, @ModelAttribute HashMap<String, String> properties,Model model) { ... }
不幸的是,当我通过单击“提交”按钮调用它时,HashMap properties 是空的。你们中有人知道如何解决这个问题吗?仅供参考:我故意选择不在这里使用传统的类绑定。原因是我想要一个动态的解决方案,使用任意类。
【问题讨论】:
标签: java spring forms hashmap thymeleaf