0
@GetMapping("add")
public String addPart(Model model)
{
model.addAttribute("suppliers", this.partService.getSupplierNames());
model.addAttribute("part", new AddPartViewModel());
return "parts/parts-add";
}
に文字列フィールドをバインドするこのThymeleafは、選択ボックス
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>
これは私がエラーを取得する唯一の場所である私のクラスです。フラグメントの残りの部分は、たとえth:field
タグを削除しても、List<String> suppliers
が選択ボックスに正しく入りこんでも正しく動作します。すなわち、同様<select>
タグにフィールド
<select class="form-control" id="supplierName" th:field="*{supplierName}">
を、それでも、私は、フォーム・バッキングBeanのフィールドに
あなたがたは、私のために仕事をしてくれました – Alexander