我有两个对象Employee
,Department
Employee 包含dept_id
. 我想要做的是Employee
在 jsp 页面的表格中显示内容。但是dept_id
我不想显示,而是想dept_name
从Department
表格中显示。到目前为止,我的控制器方法为:
public ModelAndView viewEmployee(HttpServletRequest request,
HttpServletResponse response) throws Exception {
List<Employee> employeeList = employeeService.getAllEmployee();
List<Department> departmentList = new ArrayList<Department>();
for (Employee e : employeeList) {
departmentList.add(departmentService.getDepartment(e.getDept_id()));
}
Map<String, Object> model = new HashMap<String, Object>();
model.put("employee", employeeList);
model.put("department", departmentList);
return new ModelAndView("viewEmployee", "model", model);
}
viewEmployee.jsp
<table border="1px" bordercolor="black" width=80% align="center">
<tr>
<td>Name</td>
<td>Gender</td>
<td>Salary</td>
<td>Department</td>
<td>Action</td>
</tr>
<c:forEach items="${model.employeeList}" var="element">
<tr>
<td><c:out value="${element.name}" /></td>
<td><c:out value="${element.gender}" /></td>
<td><c:out value="${element.salary}" /></td>
<td>display Department Name here </td>
<td><a
href="<c:url value="editEmployee.htm">
<c:param name="emp_id" value="${element.id}"/>
</c:url>
">Edit</a>
<a
href="<c:url value="deleteEmployee.htm">
<c:param name="emp_id" value="${element.id}"/>
</c:url>
">Delete</a>
</td>
</tr>
</c:forEach>
</table>
有什么帮助吗?我无法将地图内容显示到 jsp 页面。