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