1.问题描述: 假如有类:class Student{String sId;String sName;int age;int gradeId;} class Grade{String id;String gName;int gNo;} 有.htm要显示:sId,sName,age, gName,gNo 页面显示的内容来自两个表,如何处理? 2.解决方法: (1).在 class Student 中 加入 gName/gNo 两个字段 (2).将所有的结果放在一个map中,在页面遍历这个map。 一般情况下,在页面上显示的表格的列不会太多,最多十几个。 所以最好把查询好的结果放进键值对的值里面,而不是放对象。 (3).在有List<Student> 的情况下,遍历后,得到一个完全对应的List<Grade>,不能用map,没有下标,不能映射 比如,在jsp页面上,可以这样做: <c:forEach items="${studentList}" var="s" varStatus="status"> <tr> <td>${s.sId}</td> <td>${s.sName}</td> <td>${s.age}</td> <td>${gradeList[status.count-1].gName}</td> <td>${gradeList[status.count-1].gNo}</td> </tr> </c:forEach>
转载请注明原文地址: https://www.6miu.com/read-18949.html