0
@GetMapping("add")
public String addPart(Model model)
{
model.addAttribute("suppliers", this.partService.getSupplierNames());
model.addAttribute("part", new AddPartViewModel());
return "parts/parts-add";
}
這是我的課Thymeleaf一個String字段綁定到一個選擇框
public class AddPartViewModel
{
private String name;
private double price;
private int quantity;
private String supplierName;
//PUBLIC GETERS AND SETTERS AND AN EMPTY CONSTRUCTOR
}
Thymeleaf語法
<div class="form-group">
<label for="supplierName">Example select</label>
<select class="form-control" id="supplierName">
<option th:each="name : ${suppliers}" th:text="${name}" th:field="*{supplierName}"></option>
</select>
</div>
這是我會在錯誤的地方。剩下的片段可以正常工作,即使只是將List<String> suppliers
中的List<String> suppliers
區塊刪除到選擇框中即可。不是我試圖把日:字段中<select>
標籤爲好,即
<select class="form-control" id="supplierName" th:field="*{supplierName}">
但我仍然parcing
你們個值做的工作對我來說 – Alexander