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");
@ -57,19 +77,18 @@ public class StudentController {
} else {
list = studentService.search(page, size, keyword);
}
//PageInfo就是一个封装了分页数据的bean
PageInfo pageInfo = new PageInfo(list);
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 {
@ -82,14 +101,14 @@ 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 {
@ -101,9 +120,7 @@ public class StudentController {
if (isExist == null) {
return;
}
//如果isExist不为空说明学号已被注册
writer.write("true");
}
@RequestMapping("/addStudent")
@ -122,9 +139,10 @@ 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 {
@ -133,7 +151,6 @@ public class StudentController {
writer.write("false");
return;
}
Student s = studentService.findBySno(student.getSno());
if (s != null) {
writer.write("false");
@ -145,7 +162,6 @@ public class StudentController {
} else {
writer.write("false");
}
}
@RequestMapping("/editStudent")
@ -158,11 +174,13 @@ public class StudentController {
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 {
@ -171,25 +189,18 @@ public class StudentController {
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 {
@ -200,6 +211,5 @@ public class StudentController {
IOUtils.copy(is, outputStream);
}
}
}

Loading…
Cancel
Save