我有错误
org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/jsp/players/playersList.jsp at line 39
36: </thead>
37: <c:forEach items="${model.playersList}}" var="player" >
38: <tbody>
39: <td><c:out value="${player.id}" /> </td>
40: <td><c:out value="${player.firstName}"/> </td>
41: <td>$(player.lastName)</td>
42: <td>$(player.tournamentsIdPlusNameHistory)</td>
和
javax.el.PropertyNotFoundException: Property 'id' not found on type java.lang.String
模型是:
private int id;
private String firstName;
private String lastName;
private String city;
private Array tournamentsIdPlusNameHistory;
private Date lastActivity;
private int rating;
private String rank;
private String email;
使用这样的getter和setter:
public int getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
这是一个控制器
public ModelAndView getPlayers(Map<String, Object> model) {
List<Player> playersList = playerDao.getAll();
model.put("players", playersList);
return new ModelAndView("players/playersList", model);
}
这是.jsp文件:
<c:forEach items="${model.playersList}}" var="player" >
<tbody>
<td><c:out value="${player.id}" /> </td>
<td><c:out value="${player.firstName}"/> </td>
<td>$(player.lastName)</td>
<td>$(player.tournamentsIdPlusNameHistory)</td>
<td>$(player.lastActivity)</td>
<td>$(player.rating)</td>
<td>$(player.rank)</td>
<td>$(player.email)</td>
</tbody>
</c:forEach>
我真的不明白是什么问题,因为我发现了很多像这样的问题,并试图遵循所有的建议,但它仍然不起作用。
答案 0 :(得分:2)
您已将模型属性设置为players
,其中包含List<Players>
。在for循环中,您必须进行这样的更改,
<c:forEach items="${players}" var="player" >
<tbody>
<td><c:out value="${player.id}" /> </td>
<td><c:out value="${player.firstName}"/> </td>
<td>${player.lastName}</td>
<td>${player.tournamentsIdPlusNameHistory}</td>
<td>${player.lastActivity}</td>
<td>${player.rating}</td>
<td>${player.rank}</td>
<td>${player.email}</td>
</tbody>
</c:forEach>
打印时,您还使用了圆括号()
而不是大括号{}
。
答案 1 :(得分:0)
如果您有像
这样的实体类@Entity
class User{
@Id
int id
String name;
String password;
public String getName()//This should be getname or getName if it is something else it will cause issue
{
}
}
答案 2 :(得分:-2)
我不太确定但是 我看到'id'属性设置为私有。
是否可以使用$ {}表达式访问私有成员变量?