我有一个对象列表。该对象属于以下类:
@Entity
@Table(name="User")
public class User {
@Id
@Column(name = "userid" ,unique=true, nullable=false)
private String id;
@Column(name="firstname")
private String firstname;
@Column(name="lastname")
private String lastname;
@Column(name="title")
private String title;
@Embedded
private Address address;
@ManyToMany
@JoinTable(name="phone_user", joinColumns={@JoinColumn(name="userid")},
inverseJoinColumns={@JoinColumn(name="phoneid")})
private List<Phone> phones;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public List<Phone> getPhones() {
return phones;
}
public void setPhones(List<Phone> phones) {
this.phones = phones;
}
}
在我的控制器方法中,我将此列表添加到模型中:
model.addAttribute("lists",phone.getUsers());
在我的JSP中,我无法访问list getter方法。我需要访问getId和getFirstName getter。 这是我的JSP:
<c:forEach items="${lists}" var="listvalue">
<tr>
<td>Employee ID: <c:out value="${listvalue}"/></td>
<td>Employee Pass: <c:out value="${listvalue.getId()}"/></td>
</tr>
</c:forEach>
我收到以下错误:
org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/phoneview.jsp at line 33
第33行是:
<td>Employee Pass: <c:out value="${listvalue.getId()}"/></td>
我似乎无法弄清问题是什么。
答案 0 :(得分:1)
不应该调用方法getId()
,而应使用JavaBean样式属性:
<c:out value="${listvalue.id}"/>
它应该可以工作,因为EL(表达式语言)使用JavaBeans规范。就此规范而言,listvalue
是一个Java bean,id
是一个由getter方法getId()
读取的属性。
另请参阅: EL Wiki