0

我有两个表(实体类),需要从两者中选择并将结果传输到 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);

我必须如何纠正这个或告诉我在哪里可以阅读这个?

4

1 回答 1

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

更正确

于 2013-07-04T09:33:10.433 回答