我想将多个模型属性解析为控制器的th:value。我这样做是为了在表单中传递模型之前在同一页面中传递模型。这以前曾经奏效,但现在没有奏效
我的控制器
RequestMapping(value = "typeitem/{id}/item/tambah", method = RequestMethod.GET)
private String tambahItem(Model model, @PathVariable(value = "id") long id) {
ItemModel item = new ItemModel();
TypeItemModel typeSelected = typeItemService.getTypeItemById(id);
FormItemWrapper itemWrapper = new FormItemWrapper();
model.addAttribute("item", item);
model.addAttribute("itemWrapper", itemWrapper);
model.addAttribute("typeItem", typeSelected);
return "add-material";
}
@RequestMapping(value = "typeitem/{id}/item/tambah", params = { "addEntry" }, method = RequestMethod.POST)
private String addEntrySerialItem(Model model, @ModelAttribute TypeItemModel typeItem,
@ModelAttribute ItemModel item, @ModelAttribute FormItemWrapper itemWrapper) {
for (int i = 0; i < 3; i++) {
itemWrapper.addPengalamanToList(new SerialObject());
}
model.addAttribute("item", item);
model.addAttribute("itemWrapper", itemWrapper);
model.addAttribute("cont", 3);
model.addAttribute("typeItem", typeItem);
return "add-material";
}
我的HTML
<div class="blankspace" id="tambahDIV">
<form th:action="@{'/typeitem/'+${typeItem.id}+'/item/tambah'}"
method="POST" th:object="${item}">
<div class="boxContainer2" style="overflow-x: auto;">
<h4 style="display: inline; margin-left: 10px">Tambah Material
Baru</h4>
<hr>
<div class="col-md-12"></div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="itemName">Part</label> <input type="text"
class="form-control"
th:text="${typeItem.itemName} + ' - ' + ${typeItem.kategori} + ' - ' + ${typeItem.spesifikasi} + ' - ' + ${typeItem.type}"
disabled>
.........Some Code.......
<div class="form-group col-md-4">
<label for="merek">Jumlah</label> <input type="number"
th:field="${itemWrapper.serialCounter}" class="form-control" required>
</div>
**<div class="form-group col-md-2">
<button type="submit" class="btn btn-success btn-large"
th:value="${item}+${typeItem}+${itemWrapper}"
style="margin-top: 30px" name="addEntry">Set</button>
</div>
<div class="form-group col-md-6"></div>**
......Some Code..........
</form>
</div>
</div>
</div>
如果您在“ addEntrySerialitem”中看到我的代码,则我得到@ModelAttribute TypeItem typeItem和@ModelAttribute FormItemWrapper itemWrapper的空值
我需要从HTML中解析itemWrapper和typeItem到Controller中的addEntrySerialitem,以重用它们的值。我的@ModelAttribute没有从HTML接收任何值(请参阅“设置”按钮中的HTML部分)