我尝试了这种方式,但方法仍未初始化,它给出了 null。
模型类集属性
@OneToMany(cascade = CascadeType.ALL, mappedBy = "customer", fetch = FetchType.EAGER)
private Set<PaymentMethod> methods;
//JSP 表单
<input type="checkbox" name="customer.methods[0].type" value="CC">credit card<br>
<input type="checkbox" name="customer.methods[1].type" value="DC">debit card<br>
<input type="checkbox" name="customer.methods[2].type" value="PP">pay pal<br>
<input type="checkbox" name="customer.methods[3].type" value="BC">bank credit
</div>
你的问题很难理解,但从我乍一看,你试图访问一个列表,就好像它是一个数组,但它不是。
至少它应该是customer.getMethods().get(0).getType()
等等。
获取者是为了清楚起见。当然,你的实体也必须有getters和setter。