package controller;
import java.util.List;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import service.EmployeeService;
import entity.Employee;
import entity.FenYe;
@Controller
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@ResponseBody
@RequestMapping("/login")
public Object login(String username,String password){
if("admin".equals(username) && "admin".equals(password)){
return 1;
}else{
return 0;
}
}
@RequestMapping("/update")
public String update(Employee employee){
employeeService.update(employee);
return "index";
}
@RequestMapping("/insert")
public String insert(Employee employee){
employeeService.insert(employee);
return "index";
}
@RequestMapping("/delete")
public String delete(int id){
employeeService.delete(id);
return "index";
}
@RequestMapping("/findAllByPage")
public String findAllByPage(@RequestParam(defaultValue = "1")String page,
@RequestParam(defaultValue = "")String name,Model model){
FenYe fenye = new FenYe(page, 3, employeeService.count(name));
List<Employee> list = employeeService.findAllByPage((fenye.getCurrentPage()-1)*3, 3, name);
model.addAttribute("fenye", fenye.show());
model.addAttribute("list", list);
return "index";
}
}