繁体   English   中英

java.lang.ClassCastException:[Ljava.lang.Object; 与com.spring.model.Instruction不兼容

[英]java.lang.ClassCastException: [Ljava.lang.Object; incompatible with com.spring.model.Instruction

public List<Instruction> listPAyment() {
    Session session = this.sessionFactory.getCurrentSession();
    List<Instruction> personsList = (List<Instruction>)session.createSQLQuery(
        "SELECT INSTRUCTIONKEY, BASECURRENCY,STATUSPROC, WHENMODIFIED FROM MyDB.INSTRUCTION"
    ).list();
    EXCEPTION HERE--->    for(Instruction p : personsList){
        System.out.println( "Payment::"+ p.toString()); 
    }
    return personsList;
}

我得到java.lang.ClassCastException: [Ljava.lang.Object; incompatible with com.spring.model.Instruction java.lang.ClassCastException: [Ljava.lang.Object; incompatible with com.spring.model.Instruction上面提到的java.lang.ClassCastException: [Ljava.lang.Object; incompatible with com.spring.model.Instruction异常java.lang.ClassCastException: [Ljava.lang.Object; incompatible with com.spring.model.Instruction ,我无法找出在下面的代码中输出有什么问题。 我在模型类Instruction正确添加了toString()

请协助

[2016/09/05 15:05:01:991 GMT + 02:00] 00000040 ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper服务SRVE0068E:servlet的一个服务方法抛出异常[应用程序[SpringMVCHibernate_war]中的/WEB-INF/views/instruction.jsp]。 创建了异常:[java.lang.NumberFormatException:对于输入字符串:java.lang.NumberFormatException.forInputString(NumberFormatException.java:59)中java的java.lang.Integer.parseInt(Integer.java:460)中的“instructionKey”。 lang.Integer.parseInt(Integer.java:510)位于javax.el.ArrayELResolver.getValue(ArrayELResolver.java:46)的javax.el.ArrayELResolver.coerce(ArrayELResolver.java:166),位于javax.el.CompositeELResolver.getValue (CompositeELResolver.java:55)org.apache.el.parser.AstValue.getValue(AstValue.java:174)org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:283)atg.apache.jasper。 run.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:778)位于com.ibm._jsp._jsp._jsp._jspx_meth_c_if_0(_instruction.java:179)的com.ibm._jsp._instruction._jspx_meth_c_forEach_0(____instruction.java:131)位于javax.servlet.http.HttpServlet.serv的com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:99)中的._jsp._instruction._jspService(_instruction.java:95) ice(HttpServlet.java:668)at com.ibm.ws.cache.servlet.ServletWrapper.serviceProxied(ServletWrapper.java:307)

Jsp迭代对象:

      <c:forEach items="${listPersons}" var="instruction">
            <tr>
                <td>${instruction.instructionKey}</td>
                <td>${instruction.statusProc}</td>
                <td>${instruction.baseCurrency}</td> 
                <td>${instruction.whenModified}</td>
            </tr>
        </c:forEach>

其中model.addAttribute(“instruction”,new Instruction()); model.addAttribute(“listPersons”,this.personService.listPersons());

在控制器中定义。

你可以从数据库中提取一个名为:whatever:的类,并为该类提供将从数据库中提取的变量,并为其提供一个可以调用的toString方法? 也许?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM