我有两个表(实体类),需要从两个表中选择并将结果传输到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);
我必须如何纠正这个问题,或者告诉我在哪里可以阅读这个内容?
答案 0 :(得分:0)
我找到了这个问题的解决方案。正确的查询
select b from Categorietype c, Balance b where c.user = :user and b.user = :user
并在jsp页面上将$ {r.name}更改为r.typecategory.sum
<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.typecategory.name} </td>
</tr>
</c:forEach>
</table>
<强> PS 强> 我将查询更改为
select b.id as id, b.sum, b.description, t.name from Balance b join b.typecategory t where b.user = :user and b.typecategory = t and b.status = :status
更正确