package com.test.web;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.test.bean.Student;
import com.test.service.ISService;
import com.test.util.ExportExcel;
@Controller
public class SController {
@Autowired
private ISService service;
//登陆
@RequestMapping("/")
private ModelAndView tologin() {
return new ModelAndView("login");
}
@RequestMapping("login")
private String login(String name,String pwd,HttpSession session) {
service.login(name,pwd,session);
return "redirect:list";
}
@PostMapping("testName")
@ResponseBody
public boolean testName(String name) {
System.out.println(name+"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
return service.testName(name);
}
//学生信息列表
@RequestMapping("list")
public String list(HttpSession session,Model model, String mohu) {
if(mohu!=null) session.setAttribute("mohu", mohu);
mohu=(String) session.getAttribute("mohu");
model.addAttribute(service.list(mohu));
return "list";
}
//添加学生信息
@RequestMapping("toadd")
public String toadd() {
return "add";
}
@RequestMapping("add")
public String add(Student student) {
service.add(student);
return "redirect:list";
}
//删除学生记录
@RequestMapping("del")
public String del(String id) {
service.del(id);
return "redirect:list";
}
//修改学生信息
@RequestMapping("toupdate")
public String toupdate(String id,HttpSession session) {
Student student=service.toupdate(id);
session.setAttribute("student", student);
return "update";
}
@RequestMapping("update")
public String update(Student student) {
service.update(student);
return "redirect:list";
}
@RequestMapping("poi")
public void poi() {
ExportExcel<Student> export=new ExportExcel<>();
String title="学生信息";
String[] headersName= {"届别","班级名称","学号","姓名","出生日期","性别","状态","民族","电话","入学日期"};
String[] headersId={"data","clazz","id","name","birth","sex","state","nation","tel","indate"};
List<Student> dtoList=this.service.findAll();
String exportPath;
int i=export.exportExcel(title, headersName, headersId, dtoList, "d://学生信息.xls");
}
}