controller包里的model.addAttribute(“emps”, employees)里的"emps",对应的是list.html里的${emps},与@Mapping(“emps”)无关,"depts"同理,但html里别忘了写 ${}
@GetMapping("/emps")//对应list.html里的<tr th:each="emp:${emps}">中的${emps}
public String list(Model model) {
Collection<Employee> employees = employeeDao.getAll();
//thymeleaf默认拼串路径"classpath:/templates/xxx.html"
//public static final String DEFAULT_PREFIX = "classpath:/templates/";
model.addAttribute("emps", employees);
return "emp/list";
}
<tbody>
<tr th:each="emp:${emps}">
<td th:text="${emp.id}"></td>
<td th:text="${emp.lastName}"></td>
<td th:text="${emp.email}"></td>
<td th:text="${emp.gender}==0?'女':'男'"></td>
<td th:text="${emp.department.departmentName}"></td>
<td th:text="${#dates.format(emp.birth,'yyyy-MM-dd HH:mm:ss')}"></td>