[英]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;
}
I am getting 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
exception at above mentioned point, I am unable to find out what's wrong with casting in below code. 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
,我无法找出在下面的代码中输出有什么问题。 I have added toString()
correctly in model class Instruction
我在模型类
Instruction
正确添加了toString()
Please assist 请协助
[2016/09/05 15:05:01:991 GMT+02:00] 00000040 ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: An exception was thrown by one of the service methods of the servlet [/WEB-INF/views/instruction.jsp] in application [SpringMVCHibernate_war]. [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]。 Exception created : [java.lang.NumberFormatException: For input string: "instructionKey" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:59) at java.lang.Integer.parseInt(Integer.java:460) at java.lang.Integer.parseInt(Integer.java:510) at javax.el.ArrayELResolver.coerce(ArrayELResolver.java:166) at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:46) at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:55) at org.apache.el.parser.AstValue.getValue(AstValue.java:174) at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:283) at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:778) at com.ibm._jsp._instruction._jspx_meth_c_forEach_0(_instruction.java:131) at com.ibm._jsp._instruction._jspx_meth_c_if_0(_instruction.java:179) at com.ibm._jsp._instruction._jspService(_instruction.java:95) at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:99) at javax.servlet.http.HttpServlet.serv
创建了异常:[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)
ice(HttpServlet.java:668)at com.ibm.ws.cache.servlet.ServletWrapper.serviceProxied(ServletWrapper.java:307)
Jsp to iterate object: 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>
where model.addAttribute("instruction", new Instruction()); 其中model.addAttribute(“instruction”,new Instruction()); model.addAttribute("listPersons", this.personService.listPersons());
model.addAttribute(“listPersons”,this.personService.listPersons());
defined in controller. 在控制器中定义。
You could pull from the DB into a class named :whatever: and give that class the variables that will be pulled from the DB and give it a toString method that you can call? 你可以从数据库中提取一个名为:whatever:的类,并为该类提供将从数据库中提取的变量,并为其提供一个可以调用的toString方法? Maybe?
也许?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.