我是progrmming的新手,使用spring mvc框架开发spring MVC应用程序。我想通过使用带有2个映射实体的JSTL将数据列表到表中。
<c:forEach items="${empList}" var="emp">
<tr class="odd gradeX">
<td>${emp.icode}</td>
<td>${emp.employeeName}</td>
//problem here
//I want to get employee's phone num
<td>${emp.ph_number}</td>
</tr>
</c:forEach>
这是我的实体的例子, 1)员工实体
@Entity
public class Employee implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long employeeId;
private String employeeName;
@OneToMany(mappedBy="employee" ,cascade={CascadeType.ALL})
private List<Phone>phones;
//method getter setter }
2)电话实体
@Entity
public class Phone implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long phoneId;
private String ph_number;
@ManyToOne
private Employee employee;
//method getter setter}
3)Enployee控制器
@Controller
public class EmployeeController {
@EJB(mappedName = "ejb:/EJB//EmployeeServiceBean!com.mfu.ejb.EmployeeService")
EmployeeService empServ;
@RequestMapping("/listEmp")
public ModelAndView listEmployee(HttpServletRequest request) {
ModelAndView mv = new ModelAndView("ListEmp.jsp");
List<Employee> empList;
try {
empList = empServ.getAllEmployee();
mv.addObject("empList", empList);
} catch (Exception e) {
e.printStackTrace();
}
return mv;
}
}
谢谢你,抱歉我的英语不好。希望它有所作为。