Employee(员工实体类)、Prise(奖励表实体类),员工与奖励是一对多的关系,奖励与员工是多对一的关系。
Employee的属性名有:private Integer empId;
private String empName;
private Set pri=new HashSet();
Prise的属性名有:private Integer priId;
private String priYear;
private String priType;
private String priComment;
private Employee emp;
在ShowEmployee.jsp也面上做如下显示:
<table>
<tr>
<td>职员编号</td>
<td>职员姓名</td>
<td>荣获奖励</td>
</tr>
<logic:iterate id="employee" name="list">
<tr>
<td>${employee.empId }</td>
<td>${employee.empName }</td>
<td>${这里该怎么写啊!}</td>
</tr>
</logic:iterate>
</table>
我在ACTION中的代码是:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception { ActionForward af = null;
EmployeeForm employeeForm=(EmployeeForm)form;
Employee employee=employeeForm.getEmployee(); BaseHibernateDAO bd = new BaseHibernateDAO(); EmployeeBiz biz = new EmployeeBizImpl(); Session session = bd.getSession(); Transaction tx = null; List list = null; List<Prise> jihe = new ArrayList<Prise>(); Prise prise = null;
try { tx = session.beginTransaction(); list = biz.selectAll(); request.setAttribute("list", list); af = mapping.findForward("ShowEmploee"); for (int i = 0; i < list.size(); i++) { employee = (Employee) list.get(i); Iterator it = employee.getPri().iterator(); while (it.hasNext()) { prise = (Prise) it.next(); jihe.add(prise);
System.out.print(prise.getPriType());
}
System.out.println();
}
request.setAttribute("jihe", jihe); tx.commit(); } catch (Exception e) { if (null != tx) {
tx.rollback();
} e.printStackTrace(); } finally { session.close(); } return af;
}
里面的代码是正确的,不知道这样写是否能达到目的?
在ShowPrise.jsp上做如下显示:
<table>
<tr>
<td>编号</td>
<td>年度</td>
<td>类型</td>
<td>获奖员工</td>
<td>评语</td>
</tr>
<logic:iterate id="prise" name="list">
<tr>
<td>${prise.priId }</td>
<td>${prise.priYear }</td>
<td>${prise.priType }</td>
<td>${prise.emp.empName }</td>//这里给我报错
<td>${prise.priComment }</td>
</tr>
</logic:iterate>
</table>
帮忙看一下,在线等待帮助。解决了立即结贴!
Employee的属性名有:private Integer empId;
private String empName;
private Set pri=new HashSet();
Prise的属性名有:private Integer priId;
private String priYear;
private String priType;
private String priComment;
private Employee emp;
在ShowEmployee.jsp也面上做如下显示:
<table>
<tr>
<td>职员编号</td>
<td>职员姓名</td>
<td>荣获奖励</td>
</tr>
<logic:iterate id="employee" name="list">
<tr>
<td>${employee.empId }</td>
<td>${employee.empName }</td>
<td>${这里该怎么写啊!}</td>
</tr>
</logic:iterate>
</table>
我在ACTION中的代码是:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception { ActionForward af = null;
EmployeeForm employeeForm=(EmployeeForm)form;
Employee employee=employeeForm.getEmployee(); BaseHibernateDAO bd = new BaseHibernateDAO(); EmployeeBiz biz = new EmployeeBizImpl(); Session session = bd.getSession(); Transaction tx = null; List list = null; List<Prise> jihe = new ArrayList<Prise>(); Prise prise = null;
try { tx = session.beginTransaction(); list = biz.selectAll(); request.setAttribute("list", list); af = mapping.findForward("ShowEmploee"); for (int i = 0; i < list.size(); i++) { employee = (Employee) list.get(i); Iterator it = employee.getPri().iterator(); while (it.hasNext()) { prise = (Prise) it.next(); jihe.add(prise);
System.out.print(prise.getPriType());
}
System.out.println();
}
request.setAttribute("jihe", jihe); tx.commit(); } catch (Exception e) { if (null != tx) {
tx.rollback();
} e.printStackTrace(); } finally { session.close(); } return af;
}
里面的代码是正确的,不知道这样写是否能达到目的?
在ShowPrise.jsp上做如下显示:
<table>
<tr>
<td>编号</td>
<td>年度</td>
<td>类型</td>
<td>获奖员工</td>
<td>评语</td>
</tr>
<logic:iterate id="prise" name="list">
<tr>
<td>${prise.priId }</td>
<td>${prise.priYear }</td>
<td>${prise.priType }</td>
<td>${prise.emp.empName }</td>//这里给我报错
<td>${prise.priComment }</td>
</tr>
</logic:iterate>
</table>
帮忙看一下,在线等待帮助。解决了立即结贴!
建议用QBC查询