|
|
@ -22,15 +22,14 @@ import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Description:
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
|
|
|
|
* @Date: 2020/2/17 14:17
|
|
|
|
|
|
|
|
* @Author: PeiChen
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Controller
|
|
|
|
@Controller
|
|
|
|
@RequestMapping("/student")
|
|
|
|
@RequestMapping("/student")
|
|
|
|
public class StudentController {
|
|
|
|
public class StudentController {
|
|
|
|
|
|
|
|
|
|
|
|
private StudentService studentService;
|
|
|
|
private StudentService studentService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
public void setStudentService(StudentService studentService) {
|
|
|
|
public void setStudentService(StudentService studentService) {
|
|
|
|
this.studentService = studentService;
|
|
|
|
this.studentService = studentService;
|
|
|
@ -38,6 +37,7 @@ public class StudentController {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 查询所有学生信息
|
|
|
|
* 查询所有学生信息
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param page
|
|
|
|
* @param page
|
|
|
|
* @param size
|
|
|
|
* @param size
|
|
|
|
* @param request
|
|
|
|
* @param request
|
|
|
@ -46,160 +46,170 @@ public class StudentController {
|
|
|
|
* @throws Exception
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RequestMapping("/findAll")
|
|
|
|
@RequestMapping("/findAll")
|
|
|
|
public ModelAndView findAll(@RequestParam(name = "page", required = true, defaultValue = "1") int page, @RequestParam(name = "size", required = true, defaultValue = "5") int size, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
|
public class StudentController {
|
|
|
|
request.setCharacterEncoding("utf-8");
|
|
|
|
|
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
|
|
|
|
ModelAndView mv = new ModelAndView();
|
|
|
|
|
|
|
|
List<Student> list = null;
|
|
|
|
|
|
|
|
String keyword = request.getParameter("keyword");
|
|
|
|
|
|
|
|
if (keyword == null || keyword.trim().equals("") || keyword.length() == 0) {
|
|
|
|
|
|
|
|
list = studentService.findAll(page, size);
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
list = studentService.search(page,size,keyword);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//PageInfo就是一个封装了分页数据的bean
|
|
|
|
|
|
|
|
PageInfo pageInfo = new PageInfo(list);
|
|
|
|
|
|
|
|
mv.addObject("pageInfo",pageInfo);
|
|
|
|
|
|
|
|
mv.setViewName("student-list");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return mv;
|
|
|
|
private StudentService studentService;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@Autowired
|
|
|
|
* 根据学号删除学生
|
|
|
|
public void setStudentService(StudentService studentService) {
|
|
|
|
* @param request
|
|
|
|
this.studentService = studentService;
|
|
|
|
* @param response
|
|
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@RequestMapping("/delete")
|
|
|
|
|
|
|
|
public void delete(HttpServletRequest request,HttpServletResponse response) throws Exception {
|
|
|
|
|
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
|
|
|
|
PrintWriter writer = response.getWriter();
|
|
|
|
|
|
|
|
String sno = request.getParameter("sno");
|
|
|
|
|
|
|
|
if (sno == null || "".equals(sno) || sno.length() == 0) {
|
|
|
|
|
|
|
|
writer.write("false");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
studentService.delete(sno);
|
|
|
|
|
|
|
|
writer.write("true");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 查询所有学生信息
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param page 当前页码
|
|
|
|
|
|
|
|
* @param size 每页显示的记录数
|
|
|
|
|
|
|
|
* @param request HTTP请求对象
|
|
|
|
|
|
|
|
* @param response HTTP响应对象
|
|
|
|
|
|
|
|
* @return ModelAndView 包含分页数据和视图名称
|
|
|
|
|
|
|
|
* @throws Exception 抛出异常
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@RequestMapping("/findAll")
|
|
|
|
|
|
|
|
public ModelAndView findAll(@RequestParam(name = "page", required = true, defaultValue = "1") int page, @RequestParam(name = "size", required = true, defaultValue = "5") int size, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
|
|
|
|
|
request.setCharacterEncoding("utf-8");
|
|
|
|
|
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
|
|
|
|
ModelAndView mv = new ModelAndView();
|
|
|
|
|
|
|
|
List<Student> list = null;
|
|
|
|
|
|
|
|
String keyword = request.getParameter("keyword");
|
|
|
|
|
|
|
|
if (keyword == null || keyword.trim().equals("") || keyword.length() == 0) {
|
|
|
|
|
|
|
|
list = studentService.findAll(page, size);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
list = studentService.search(page, size, keyword);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PageInfo pageInfo = new PageInfo(list);
|
|
|
|
|
|
|
|
mv.addObject("pageInfo", pageInfo);
|
|
|
|
|
|
|
|
mv.setViewName("student-list");
|
|
|
|
|
|
|
|
return mv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 判断指定学号是否存在
|
|
|
|
* 根据学号删除学生
|
|
|
|
* @param request
|
|
|
|
*
|
|
|
|
* @param response
|
|
|
|
* @param request HTTP请求对象
|
|
|
|
* @throws Exception
|
|
|
|
* @param response HTTP响应对象
|
|
|
|
*/
|
|
|
|
* @throws Exception 抛出异常
|
|
|
|
@RequestMapping("/isExist")
|
|
|
|
*/
|
|
|
|
public void isSnoExist(HttpServletRequest request,HttpServletResponse response) throws Exception {
|
|
|
|
@RequestMapping("/delete")
|
|
|
|
request.setCharacterEncoding("utf-8");
|
|
|
|
public void delete(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
PrintWriter writer = response.getWriter();
|
|
|
|
PrintWriter writer = response.getWriter();
|
|
|
|
String sno = request.getParameter("sno");
|
|
|
|
String sno = request.getParameter("sno");
|
|
|
|
Student isExist = studentService.findBySno(sno);
|
|
|
|
if (sno == null || "".equals(sno) || sno.length() == 0) {
|
|
|
|
if (isExist == null) {
|
|
|
|
writer.write("false");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
studentService.delete(sno);
|
|
|
|
|
|
|
|
writer.write("true");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//如果isExist不为空说明学号已被注册
|
|
|
|
|
|
|
|
writer.write("true");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 判断指定学号是否存在
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param request HTTP请求对象
|
|
|
|
|
|
|
|
* @param response HTTP响应对象
|
|
|
|
|
|
|
|
* @throws Exception 抛出异常
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@RequestMapping("/isExist")
|
|
|
|
|
|
|
|
public void isSnoExist(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
|
|
|
|
|
request.setCharacterEncoding("utf-8");
|
|
|
|
|
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
|
|
|
|
PrintWriter writer = response.getWriter();
|
|
|
|
|
|
|
|
String sno = request.getParameter("sno");
|
|
|
|
|
|
|
|
Student isExist = studentService.findBySno(sno);
|
|
|
|
|
|
|
|
if (isExist == null) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
writer.write("true");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/addStudent")
|
|
|
|
@RequestMapping("/addStudent")
|
|
|
|
public ModelAndView addStudent(HttpServletRequest request) throws Exception {
|
|
|
|
public ModelAndView addStudent(HttpServletRequest request) throws Exception {
|
|
|
|
request.setCharacterEncoding("utf-8");
|
|
|
|
request.setCharacterEncoding("utf-8");
|
|
|
|
ModelAndView mv = new ModelAndView();
|
|
|
|
ModelAndView mv = new ModelAndView();
|
|
|
|
String dorm_id = request.getParameter("dorm_id");
|
|
|
|
String dorm_id = request.getParameter("dorm_id");
|
|
|
|
if (dorm_id != null) {
|
|
|
|
if (dorm_id != null) {
|
|
|
|
mv.addObject("dorm_id",dorm_id);
|
|
|
|
mv.addObject("dorm_id", dorm_id);
|
|
|
|
mv.setViewName("dormStudent-add");
|
|
|
|
mv.setViewName("dormStudent-add");
|
|
|
|
|
|
|
|
return mv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mv.setViewName("student-add");
|
|
|
|
return mv;
|
|
|
|
return mv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mv.setViewName("student-add");
|
|
|
|
|
|
|
|
return mv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 添加学生信息
|
|
|
|
* 添加学生信息
|
|
|
|
* @param student
|
|
|
|
*
|
|
|
|
* @param response
|
|
|
|
* @param student 学生对象
|
|
|
|
* @throws Exception
|
|
|
|
* @param response HTTP响应对象
|
|
|
|
*/
|
|
|
|
* @throws Exception 抛出异常
|
|
|
|
@RequestMapping("/add")
|
|
|
|
*/
|
|
|
|
public void add(Student student,HttpServletResponse response) throws Exception {
|
|
|
|
@RequestMapping("/add")
|
|
|
|
PrintWriter writer = response.getWriter();
|
|
|
|
public void add(Student student, HttpServletResponse response) throws Exception {
|
|
|
|
if (student == null || studentService.findBySno(student.getSno()) != null) {
|
|
|
|
PrintWriter writer = response.getWriter();
|
|
|
|
writer.write("false");
|
|
|
|
if (student == null || studentService.findBySno(student.getSno()) != null) {
|
|
|
|
return;
|
|
|
|
writer.write("false");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Student s = studentService.findBySno(student.getSno());
|
|
|
|
|
|
|
|
if (s != null) {
|
|
|
|
|
|
|
|
writer.write("false");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean isAdd = studentService.add(student);
|
|
|
|
|
|
|
|
if (isAdd) {
|
|
|
|
|
|
|
|
writer.write("true");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
writer.write("false");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Student s = studentService.findBySno(student.getSno());
|
|
|
|
@RequestMapping("/editStudent")
|
|
|
|
if (s != null) {
|
|
|
|
public ModelAndView editStudent(HttpServletRequest request) throws Exception {
|
|
|
|
writer.write("false");
|
|
|
|
ModelAndView mv = new ModelAndView();
|
|
|
|
return;
|
|
|
|
request.setCharacterEncoding("utf-8");
|
|
|
|
|
|
|
|
String sno = request.getParameter("sno");
|
|
|
|
|
|
|
|
Student stu = studentService.findBySno(sno);
|
|
|
|
|
|
|
|
mv.addObject("stu", stu);
|
|
|
|
|
|
|
|
mv.setViewName("student-edit");
|
|
|
|
|
|
|
|
return mv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boolean isAdd = studentService.add(student);
|
|
|
|
|
|
|
|
if (isAdd) {
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 修改学生信息
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param student 学生对象
|
|
|
|
|
|
|
|
* @param response HTTP响应对象
|
|
|
|
|
|
|
|
* @throws Exception 抛出异常
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@RequestMapping("/update")
|
|
|
|
|
|
|
|
public void update(Student student, HttpServletResponse response) throws Exception {
|
|
|
|
|
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
|
|
|
|
PrintWriter writer = response.getWriter();
|
|
|
|
|
|
|
|
if (student == null || student.getId() == null) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (student.getName() == null || "".equals(student.getName()) || student.getName().length() == 0 || student.getSex() == null || student.getSex().length() == 0 || "".equals(student.getSex()) || student.getSno() == null || "".equals(student.getSno()) || student.getSno().length() == 0 || student.getPhone() == null || "".equals(student.getPhone()) || student.getPhone().length() == 0 || student.getStu_class() == null || "".equals(student.getStu_class()) || student.getStu_class().length() == 0 || student.getPlace() == null || "".equals(student.getPlace()) || student.getPlace().length() == 0 || student.getDorm_id() == null || "".equals(student.getDorm_id()) || student.getDorm_id().length() == 0 || student.getTeacher() == null || "".equals(student.getTeacher()) || student.getTeacher().length() == 0) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
studentService.update(student);
|
|
|
|
writer.write("true");
|
|
|
|
writer.write("true");
|
|
|
|
}else {
|
|
|
|
|
|
|
|
writer.write("false");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 导出学生数据为Excel
|
|
|
|
@RequestMapping("/editStudent")
|
|
|
|
*
|
|
|
|
public ModelAndView editStudent(HttpServletRequest request) throws Exception {
|
|
|
|
* @param response HTTP响应对象
|
|
|
|
ModelAndView mv = new ModelAndView();
|
|
|
|
* @throws Exception 抛出异常
|
|
|
|
request.setCharacterEncoding("utf-8");
|
|
|
|
*/
|
|
|
|
String sno = request.getParameter("sno");
|
|
|
|
@RequestMapping("/export")
|
|
|
|
Student stu = studentService.findBySno(sno);
|
|
|
|
public void export(HttpServletResponse response) throws Exception {
|
|
|
|
mv.addObject("stu",stu);
|
|
|
|
InputStream is = studentService.getInputStream();
|
|
|
|
mv.setViewName("student-edit");
|
|
|
|
response.setContentType("application/vnd.ms-excel");
|
|
|
|
return mv;
|
|
|
|
response.setHeader("contentDisposition", "attachment;filename=studentsInfo.xls");
|
|
|
|
}
|
|
|
|
ServletOutputStream outputStream = response.getOutputStream();
|
|
|
|
/**
|
|
|
|
IOUtils.copy(is, outputStream);
|
|
|
|
* 修改学生信息
|
|
|
|
|
|
|
|
* @param student
|
|
|
|
|
|
|
|
* @param response
|
|
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@RequestMapping("/update")
|
|
|
|
|
|
|
|
public void update(Student student,HttpServletResponse response) throws Exception {
|
|
|
|
|
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
|
|
|
|
PrintWriter writer = response.getWriter();
|
|
|
|
|
|
|
|
if (student == null || student.getId() == null) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (student.getName() == null || "".equals(student.getName()) || student.getName().length() == 0
|
|
|
|
|
|
|
|
|| student.getSex() == null || student.getSex().length() == 0 || "".equals(student.getSex())
|
|
|
|
|
|
|
|
|| student.getSno() == null || "".equals(student.getSno()) || student.getSno().length() == 0
|
|
|
|
|
|
|
|
|| student.getPhone() == null || "".equals(student.getPhone()) || student.getPhone().length() == 0
|
|
|
|
|
|
|
|
|| student.getStu_class() == null || "".equals(student.getStu_class()) || student.getStu_class().length() == 0
|
|
|
|
|
|
|
|
|| student.getPlace() == null || "".equals(student.getPlace()) || student.getPlace().length() == 0
|
|
|
|
|
|
|
|
|| student.getDorm_id() == null || "".equals(student.getDorm_id()) || student.getDorm_id().length() == 0
|
|
|
|
|
|
|
|
|| student.getTeacher() == null || "".equals(student.getTeacher()) || student.getTeacher().length() == 0 ) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
studentService.update(student);
|
|
|
|
|
|
|
|
writer.write("true");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 导出学生数据为Excel
|
|
|
|
|
|
|
|
* @param response
|
|
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@RequestMapping("/export")
|
|
|
|
|
|
|
|
public void export(HttpServletResponse response) throws Exception {
|
|
|
|
|
|
|
|
InputStream is = studentService.getInputStream();
|
|
|
|
|
|
|
|
response.setContentType("application/vnd.ms-excel");
|
|
|
|
|
|
|
|
response.setHeader("contentDisposition", "attachment;filename=studentsInfo.xls");
|
|
|
|
|
|
|
|
ServletOutputStream outputStream = response.getOutputStream();
|
|
|
|
|
|
|
|
IOUtils.copy(is,outputStream);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|