Spring - Hibernate - 列表显示错误:java.lang.NumberFormatException:对于输入字符串:“luce”

时间:2015-12-04 14:10:58

标签: java hibernate jsp spring-mvc

早上好。

渲染我的JSP页面时遇到NumberFormatException问题。

我有一个模型,其中有一个ManyToOne注释与另一个模型

Illuminazione.java(ManyToOne与Luce.java的关系)

// showing only the interesting part
@ManyToOne
    @JoinColumn(name = "id_luce")
    public Luce getLuce() {
        return this.luce;
    }

    public void setLuce(Luce luce) {
        this.luce = luce;
    }

在我的控制器中,我必须显示加入查询的结果,而我无法使用Hibernate Criteria(至少,这是我的技能......)

这是控制器中的方法

@RequestMapping(value = {path+"/illuminazione"}, method = RequestMethod.GET)
public String lightsSituation(ModelMap model){
    List <Illuminazione> illuminazione = illuminazioneService.showLightsSituation();
    model.addAttribute("illuminazione", illuminazione);
    return path+"/illuminazione";
}
服务类中的

showLightsSituation来自对应的DAO实现,即:

public List<Illuminazione> showLightsSituations() {

        String query = "select `id_luce`, `isLit`, `date_time` from illuminazione i inner join ";
        query += "(SELECT `id_luce` as numeroLuce2, max(date_time) as MaxDate from illuminazione group by `id_luce`)";
        query += "ill on i.`id_luce`=ill.`numeroLuce2` and i.`date_time` = ill.MaxDate order by i.`id_luce` asc";

        @SuppressWarnings("unchecked")
        List <Illuminazione> lista = getSession().createSQLQuery(query).list();

        return lista;
    }

现在,在我的illuminazione.jsp中,我希望以这种方式显示Illuminazione对象的值以及来自Luce的链接

<c:forEach items="${illuminazione}" var="ill">
        <tbody>
        <tr>
            <td><div class="list-field">${ill.luce.numeroLuce}</div></td>
            <td><div class="list-field">${ill.luce.nomeLuce}</div></td>
            <td><div class="list-field">${ill.isLit}</div></td>
            <td><div class="list-field">${ill.dateTime}</div></td>

            <td class="actions"><a class="pull-right" href="<c:url value='/lights/${ill.idEvento}' />"><span class="glyphicon glyphicon-edit"></span></a></td>
        </tr>
        </c:forEach>

其中numeroLucenomeLuce是Luce.java中与Illuminazione.java相关联的字段。

我收到此异常

org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/pages/lights/illuminazione.jsp at line 115

112:         <c:forEach items="${illuminazione}" var="ill">
113:         <tbody>
114:         <tr>
115:             <td><div class="list-field">${ill.luce.numeroLuce}</div></td>
116:             <td><div class="list-field">${ill.luce.nomeLuce}</div></td>
117:             <td><div class="list-field">${ill.isLit}</div></td>
118:             <td><div class="list-field">${ill.dateTime}</div></td>

引起的

java.lang.NumberFormatException: For input string: "luce"
    java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    java.lang.Integer.parseInt(Integer.java:580)
    java.lang.Integer.parseInt(Integer.java:615)
    javax.el.ArrayELResolver.coerce(ArrayELResolver.java:151)
    javax.el.ArrayELResolver.getValue(ArrayELResolver.java:64)
    ....
    ....

问题是我可以尝试以这种方式使用List的索引迭代视图${ill[1]}等等,但是如何管理MayToOne关系?

由于

0 个答案:

没有答案