有一段代码:
String HQL_STRING = new String( "FROM Restaurant rest where rest.RId=1 ");
String []userInfo=new String[1];
//userInfo[0]=curUser.getUserId().toString();
List restaurants = restaurantDAO.getHibernateTemplate().find(HQL_STRING);
在JSP能够正确显示Restaurant 的内容,例如name
但是,当我把HQL改为:
String HQL_STRING = new String( "FROM Restaurant rest, MyRestaurant myRest where rest.RId= myRest.id.RId and myRest.id.userId=1 ");
查询得到的list在jsp就得到这样的错误:
javax.servlet.jsp.el.ELException: The ". " operator was supplied with an index value of type "java.lang.String " to be applied to a List or array, but that value cannot be converted to an integer.
org.apache.commons.el.Logger.logError(Logger.java:481)
org.apache.commons.el.Logger.logError(Logger.java:498)
org.apache.commons.el.Logger.logError(Logger.java:566)
org.apache.commons.el.ArraySuffix.evaluate(ArraySuffix.java:227)
org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:263)
org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:190)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:929)
org.apache.jsp.welcome_jsp._jspService(welcome_jsp.java:133)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
是否多表查询返回的list和单表的不一样呢?
JSP代码:
<logic:present name= "restaurants ">
<logic:iterate id= "element " name= "restaurants ">
<tr>
<td align= "left ">
<span lang= "EN-US " style= "font-size: 9.0pt; font-family: 宋体; color: #006600 ">
<a href= "/queryRest.do?r_id=${element.RId} "> <bean:write name= "element " property= "name "/> </a>
</span>
</td>
</tr>
</logic:iterate>
</logic:present>
谁知道为什么啊?谢谢!
------解决方案--------------------
你是多表查询,list里面一个元素包含了一个Restaurant对象,一个MyRestaurant对象.你因该取其中一个放到传到页面的list中
------解决方案--------------------
怎么取?
------解决方案--------------------
晕哦````````
怎么是where rest.RId= myRest.id.RId and myRest.id.userId=1 "); 这样写类
是 where rest.RId= myRest.RId and myRest.userId=1 ");