我的弹簧控制器发送对象"部门"我的表格得到了它 并且需要检查员工检查所有部门的工作量 保存效果很好但是当用户编辑员工时,他需要查看已经检查过的作业。
要使它工作,我需要使它像:th:checked =" $ {jobs.contains($ {job.id})}" 但我想我不能将属性值放在其他属性值中。
<div th:each="job : ${department.jobList}" class="col-md-4">
<fieldset class="form-group">
<label class="custom-control custom-checkbox">
<input name="jobs" th:checked="${jobs.contains(34L)}" th:value="${job.id}" type="checkbox" class="custom-control-input"/>
<span th:text="${job.name}" class="custom-control-description"></span>
<span class="custom-control-indicator"></span>
</label>
</fieldset>
</div>
我的控制员:
// Edit employee page
@RequestMapping("/panel/{workPlaceName}/employees/{id}")
public String editEmployeesPage(Model model, HttpSession httpSession, HttpServletRequest request, @PathVariable Long id) {
// Auto login check
WorkPlace workPlace = new WorkPlace();
Employee employee = new Employee();
Object logInTemp = httpSession.getAttribute ("loggedInUser");
if (logInTemp != null) {
Object tempLogIn = httpSession.getAttribute ("loggedInUser");
LogIn logIn = (LogIn) tempLogIn;
workPlace = workPlaceService.findById(logIn.getUserName());
model.addAttribute("workPlace",workPlace);
employee = employeeService.findById(id);
if(!model.containsAttribute("employee")) {
model.addAttribute("employee", employee);
}
} else {
return "redirect:/";
}
// END of Auto login check
ArrayList<Long> jobs = new ArrayList<>();
for (int i = 0; i < employee.getJobList().size(); i++) {
jobs.add(employee.getJobList().get(i).getId());
}
model.addAttribute("jobs", jobs);
model.addAttribute("action", "/panel/" + workPlace.getName() + "/employees/" + employee.getId());
return "workplace/editEmployee";
}
答案 0 :(得分:0)
好的答案是:th:checked =“$ {jobs.contains(job.id)}”
我的错误是:th:checked =“$ {jobs.contains($ {job.id})}”