result页面:
<!DOCTYPE html><html lang="en" xmlns:th="http://www.thymeleaf.org"><head><meta charset="UTF-8"><title>Title</title></head><body><table align="center" border="1" cellpadding="0"><tr><th >id</th><th>lastName</th><th>email</th><th>gender</th><th>function</th></tr><tr th:each="employee : ${employeesList}"><td th:text="${employee.id}"></td><td th:text="${employee.lastName}"></td><td th:text="${employee.email}"></td><td th:text="${employee.gender}"></td><td ><a href="">update</a><a href="">delete</a></td></tr></table></body></html>
Controller:
package com.way.controller;
import com.way.dao.EmployeeDao;
import com.way.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Collection;
@Controller
public class EmployeeController {
@Autowired
private EmployeeDao employeeDao;
@RequestMapping(value = "/selectAll",method = RequestMethod.GET)
public String selectAll(Model model){
Collection<Employee> employeesList = employeeDao.getAll();
model.addAttribute("employeesList",employeesList);
return "result";
}
}
输出结果:
