控制器1:
@RequestMapping(value = "/allEmployees", method = RequestMethod.GET)
public String getAllEmployees(@ModelAttribute("employeeListForm") EmployeeListForm employeeListForm, HttpServletRequest request, HttpServletResponse response, Model model, BindingResult errors) throws Exception {
List<Employee> subList = null;
allEmployees = empService.getAllEmployees(categoryId);
employeeListForm.setAllEmployees("allEmployees");
employeeListForm.setCategory("IT");
model.addAttribute("etcSearchForm", etcSearchForm);
return ALL_EMP_VIEW;
}
控制器2:
@RequestMapping(value = "/EmployeeDetail", method = RequestMethod.GET)
public String getEmpDetail((@ModelAttribute("empDetailForm") EmployeeDetailForm empDetailForm, HttpServletRequest request, HttpServletResponse response, Model model, BindingResult errors) throws Exception {
/*there is no direct approach to get the employee by id how should I get the
employee object from list page to deatil page
*/
empDetailForm.setSalary(emp.getSalary());
empDetailForm.setTitle(emp.getTitle());
empDetailForm.setName(emp.getName());
model.addAttribute("empDetailForm", empDetailForm);
return ALL_EMP_Detail_Form;
}
查看:
<div th:if="${allEmplListForm.aAllEmployees.size() > 0}" th:each="emp : ${allEmplListForm.aAllEmployees}" th:object="${emp}" >
<a th:href="@{/EmployeeDetail)}" class="link">
<div><p class="name" th:text="*{name}"></p></div>
<div><p th:text="*{date}"></p> <p th:text="*{title}"></p></div>
<div><p class="salary" th:text="*{salary}"></p></div>
</a>
</div>
我在一个页面中显示员工列表,当我点击员工时,它必须带我到详细信息页面(控制器2),其中没有直接的服务方法来通过id或名称或其他方式获得员工。
我应该如何将我的员工对象从视图发送到控制器。点击链接,它应该进入详细页面。