我有两个表(实体类),需要从两者中选择并将结果传输到 jsp 页面。
我的平衡实体:
@Entity
@NamedQuery (name = "findLastFiveTransaction",
query = "select c, b from Categorietype c, Balance b where c.user = :user and b.user = :user")
public class Balance implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private String id;
private BigDecimal sum;
@Column(name="Description")
private String descrip;
我的类别实体:
@Entity
public class Categorietype implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private String id;
private String name;
//bi-directional many-to-one association to Balance
@OneToMany(mappedBy="categorietype")
private List<Balance> balances;
//bi-directional many-to-one association to User
@ManyToOne
@JoinColumn(name="UserID")
private User user;
EJB 类中的方法:
public List getUserTransaction(User user) {
return em.createNamedQuery("findLastFiveTransaction").setParameter("user", user).getResultList();
}
我在jsp页面上的代码:
<table border="1">
<tr>
<th>Sum</th>
<th>Descrip</th>
<th>Name</th>
</tr>
<c:forEach items="${result}" var="r">
<tr>
<td> ${r.sum} </td>
<td> ${r.descrip} </td>
<td> ${r.name} </td>
</tr>
</c:forEach>
</table>
在这种变体中,我收到消息
org.apache.jasper.JasperException:java.lang.NumberFormatException:对于输入字符串:“sum”
我的问题是如何解析传输到jsp页面的数据。我从我的 servlet 传输数据:
List result = balance.getUserTransaction(user);
request.setAttribute("result", result );
request.getRequestDispatcher("finance.jsp").forward(request, response);
我必须如何纠正这个或告诉我在哪里可以阅读这个?