branch_shen
shen 3 months ago
parent e87530308b
commit 193fa5b67e

@ -22,15 +22,14 @@ import java.util.List;
/**
* Description:
*
* @Date: 2020/2/17 14:17
* @Author: PeiChen
*/
@Controller
@RequestMapping("/student")
public class StudentController {
private StudentService studentService;
@Autowired
public void setStudentService(StudentService studentService) {
this.studentService = studentService;
@ -38,6 +37,7 @@ public class StudentController {
/**
*
*
* @param page
* @param size
* @param request
@ -46,6 +46,26 @@ public class StudentController {
* @throws Exception
*/
@RequestMapping("/findAll")
public class StudentController {
private StudentService studentService;
@Autowired
public void setStudentService(StudentService studentService) {
this.studentService = studentService;
}
/**
*
*
* @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");
@ -54,25 +74,24 @@ public class StudentController {
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);
} else {
list = studentService.search(page, size, keyword);
}
//PageInfo就是一个封装了分页数据的bean
PageInfo pageInfo = new PageInfo(list);
mv.addObject("pageInfo",pageInfo);
mv.addObject("pageInfo", pageInfo);
mv.setViewName("student-list");
return mv;
}
/**
*
* @param request
* @param response
* @throws Exception
*
* @param request HTTP
* @param response HTTP
* @throws Exception
*/
@RequestMapping("/delete")
public void delete(HttpServletRequest request,HttpServletResponse response) throws Exception {
public void delete(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setCharacterEncoding("utf-8");
PrintWriter writer = response.getWriter();
String sno = request.getParameter("sno");
@ -82,17 +101,17 @@ public class StudentController {
}
studentService.delete(sno);
writer.write("true");
}
/**
*
* @param request
* @param response
* @throws Exception
*
* @param request HTTP
* @param response HTTP
* @throws Exception
*/
@RequestMapping("/isExist")
public void isSnoExist(HttpServletRequest request,HttpServletResponse response) throws Exception {
public void isSnoExist(HttpServletRequest request, HttpServletResponse response) throws Exception {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter writer = response.getWriter();
@ -101,9 +120,7 @@ public class StudentController {
if (isExist == null) {
return;
}
//如果isExist不为空说明学号已被注册
writer.write("true");
}
@RequestMapping("/addStudent")
@ -112,7 +129,7 @@ public class StudentController {
ModelAndView mv = new ModelAndView();
String dorm_id = request.getParameter("dorm_id");
if (dorm_id != null) {
mv.addObject("dorm_id",dorm_id);
mv.addObject("dorm_id", dorm_id);
mv.setViewName("dormStudent-add");
return mv;
}
@ -122,18 +139,18 @@ public class StudentController {
/**
*
* @param student
* @param response
* @throws Exception
*
* @param student
* @param response HTTP
* @throws Exception
*/
@RequestMapping("/add")
public void add(Student student,HttpServletResponse response) throws Exception {
public void add(Student student, HttpServletResponse response) throws Exception {
PrintWriter writer = response.getWriter();
if (student == null || studentService.findBySno(student.getSno()) != null) {
writer.write("false");
return;
}
Student s = studentService.findBySno(student.getSno());
if (s != null) {
writer.write("false");
@ -142,10 +159,9 @@ public class StudentController {
boolean isAdd = studentService.add(student);
if (isAdd) {
writer.write("true");
}else {
} else {
writer.write("false");
}
}
@RequestMapping("/editStudent")
@ -154,42 +170,37 @@ public class StudentController {
request.setCharacterEncoding("utf-8");
String sno = request.getParameter("sno");
Student stu = studentService.findBySno(sno);
mv.addObject("stu",stu);
mv.addObject("stu", stu);
mv.setViewName("student-edit");
return mv;
}
/**
*
* @param student
* @param response
* @throws Exception
*
* @param student
* @param response HTTP
* @throws Exception
*/
@RequestMapping("/update")
public void update(Student student,HttpServletResponse response) throws Exception {
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 ) {
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
*
* @param response HTTP
* @throws Exception
*/
@RequestMapping("/export")
public void export(HttpServletResponse response) throws Exception {
@ -197,9 +208,8 @@ public class StudentController {
response.setContentType("application/vnd.ms-excel");
response.setHeader("contentDisposition", "attachment;filename=studentsInfo.xls");
ServletOutputStream outputStream = response.getOutputStream();
IOUtils.copy(is,outputStream);
IOUtils.copy(is, outputStream);
}
}
}

Loading…
Cancel
Save