有谁知道如何在JSP上使用可选对象吗?
我有一门课:
@Entity
@Table(name = "projects")
public class Project {
@Expose
@ManyToOne
@JoinColumn(name = "customer_id")
private Customer endCustomer;
....
public Optional<Customer> getEndCustomer() {
return Optional.ofNullable(endCustomer);
}
public void setEndCustomer(Customer endCustomer) {
this.endCustomer = endCustomer;
}
....
}我有jsp:
<td>
<form:select class="form-control" id="endCustomer" path="endCustomer.id" tabindex="4">
<form:options items="${endCustomers}" itemValue="id" itemLabel="name"/>
</form:select>
</td>
这个部分不起作用的原因很明显:path="endCustomer.id"
有解决办法吗?谢谢!
发布于 2017-09-01 17:20:27
试试这样的东西
<td>
<form:select class="form-control" id="endCustomer" path="${endCustomer.get().id}" tabindex="4">
<form:options items="${endCustomers}" itemValue="id" itemLabel="name"/>
</form:select>
</td>https://stackoverflow.com/questions/45996695
复制相似问题