hql语句是查一个表时可以这样写 ${stu.name} 两个表联合这样写 页面出错 这个是我的hql语句 hql="from Stuclass sc,Student s where sc.id=s.stuclass.id and sc.id=1"; 错误: javax.servlet.ServletException: 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.
hql="from Stuclass sc,Student s where sc.id=s.class_id and sc.id=1"; sc.id =======>班级表中的班级id s.class_id =====>学生表中的班级id
<c:forEach var="stu" items="${requestScope.student}">
<tr><td>${stu.key1}</td><td>${stu.key2}</td></tr>
</c:forEach>
打个比方,比如你的父集合叫student,里面的每一个对象还包含一个子集合叫love
<logic:iterate name="student" id="stu">
<logic:iterate name="stu" property="love" id="stuLove">
<bean:write name="stuLove">
</logic:iterate>
</logic:iterate>
hql="from Stuclass sc,Student s where sc.id=s.stuclass.id and sc.id=1";
我是通过班级表的ID(id)等于学生表的班级ID(classid)并且班级表的ID(id=1)查结果的
最终显示的是班级ID=1的所有的学生信息 包括班级表里的名称等页面是这样写的
<logic:iterate id="stu" name="student">
<tr>
<td align="center">这里该怎样写</td>
...
</tr>
</logic:iterate>
student 学生信息集合
name: 学生姓名
age: 年龄
class_Id: 学生表中的班级Idclass 班级表
classId: 班级id
className: 班级名称因为是多表关联,那每一个学生对象中 class_Id 其实是班级对象
<c:forEach var="stu" items="${requestScope.student}">
<tr>
<td>${stu.name}</td> //姓名
<td>${stu.age }</td> //年龄
<td>${stu.class_Id.className}</td> //学生所在班级名称
</tr>
</c:forEach>
两个表联合这样写 页面出错
这个是我的hql语句
hql="from Stuclass sc,Student s where sc.id=s.stuclass.id and sc.id=1";
错误:
javax.servlet.ServletException: 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.
s.class_id =====>学生表中的班级id
java.util.List l=(java.util.List)request.getAttribute("list");
java.util.Iterator i=l.iterator();
while(i.hasNext()){
object[] d=(object[])i.next();<%=d[0]%>
<%=d[0]%>最后得到的放一个数组里,遍历就可以得到了
这方法我用过
班级的名称 用${stu.stuclass.className} 就出来了 谢谢大家
又回到用jstl了 struts标签也没用到