/** * 管理员对注册人员进行管理 * * @return */ public String registerManage() { init(); registers = new ArrayList<Register>(); int pageNow = 1; int pageCount = 0; int pageSize = 10; if (request.getParameter("pageNow") != null) { pageNow = Integer.parseInt(request.getParameter("pageNow")); } registers = personService.getList(Register.class, pageSize * (pageNow - 1), pageSize, null); pageCount = personService.getPageCount(Register.class, pageSize); request.setAttribute("registers", registers); request.setAttribute("pageCount", pageCount); request.setAttribute("pageNow", pageNow); return "registerManageSuccess"; }
/** * 管理员对学生进行管理 * * @return */ public String studentManage() { init(); students = new ArrayList<Student>(); int pageNow = 1; int pageCount = 0; int pageSize = 10; if (request.getParameter("pageNow") != null) { pageNow = Integer.parseInt(request.getParameter("pageNow")); } students = personService.getList(Student.class, pageSize * (pageNow - 1), pageSize, null); pageCount = personService.getPageCount(Student.class, pageSize); request.setAttribute("students", students); request.setAttribute("pageCount", pageCount); request.setAttribute("pageNow", pageNow); return "studentManageSuccess"; }
/** * 添加一个教师信息 * * @return */ public String addT() throws Exception { if (pictureUpload() != null) { teacher.setPictureUrl(pictureUpload()); } personService.saveTeacher(teacher); request.setAttribute("SUCCESS", "添加教师成功"); return "addSuccess"; }
/** * 添加一个注册人员信息 * * @return * @throws Exception */ public String addR() throws Exception { init(); if (pictureUpload() != null) { register.setImageUrl(pictureUpload()); } personService.saveReister(register); request.setAttribute("SUCCESS", "添加注册人员成功"); return "addSuccess"; }
/** * 添加一个学生信息 * * @return * @throws Exception */ public String addS() throws Exception { init(); if (pictureUpload() != null) { student.setImageUrl(pictureUpload()); } personService.saveStudent(student); request.setAttribute("SUCCESS", "添加学生成功"); return "addSuccess"; }
/** * 处理添加管理员 * * @return */ public String addM() { init(); String userid = request.getParameter("userid"); String username = request.getParameter("username"); String userpass = request.getParameter("userpass"); personService.saveManager(userid, username, userpass); request.setAttribute("SUCCESS", "添加管理员成功"); return "addSuccess"; // 这里依然返回添加人员页面 }
/** * 删除一条记录 * * @return */ public String deleteOne() { init(); String id = request.getParameter("id"); Integer type = Integer.parseInt(request.getParameter("type")); try { personService.deleteOne(id, type); response.getWriter().write("ok"); response.flushBuffer(); response.getWriter().close(); } catch (IOException e) { e.printStackTrace(); } return NONE; }
/** * 检查ID是否可用 * * @return */ public String checkID() { init(); String userID = request.getParameter("id"); Integer userType = Integer.parseInt(request.getParameter("type")); if (personService.checkID(userID, userType)) { try { response.getWriter().write("ok"); response.flushBuffer(); response.getWriter().close(); } catch (IOException e) { e.printStackTrace(); } } return NONE; }
/** * 处理教师信息的修改 * * @return * @throws IOException * @throws Exception */ public String updateTDeal() throws Exception { init(); if (pictureUpload() != null) { teacher.setPictureUrl(pictureUpload()); if (oldPicturePath != null) { // 设置了新的图片就删除原来的图片 File file = new File(oldPicturePath); if (file.exists()) { file.delete(); } } } personService.updateTeacher(teacher); response.getWriter().write("<script type='text/javascript'> alert('修改教师信息成功')</script>"); response.flushBuffer(); response.getWriter().close(); return NONE; }
public String deleteChecked() { init(); Integer type = Integer.parseInt(request.getParameter("type")); String resoult = request.getParameter("resoult"); String[] strings = resoult.split(","); try { for (String string : strings) { personService.deleteOne(string, type); } response.getWriter().write("ok"); response.flushBuffer(); response.getWriter().close(); } catch (IOException e) { e.printStackTrace(); } return NONE; }
/** * 对注册人员信息的修改,可以是注册人员本身或者管理员 * * @return */ public String updateR() { init(); String registerId = request.getParameter("registerId"); // 从请求参数过来的是老师更改 if (registerId == null) { registerId = request.getSession().getAttribute("USER_ID").toString(); // 从session获得的是注册人员更改的 } Register register = personService.getRegister(registerId); request.setAttribute("register", register); String imageUrl = register.getImageUrl(); if (imageUrl != null) { oldPicturePath = imageUrl; imageUrl = imageUrl.substring(imageUrl.lastIndexOf("\\") + 1); String relativeUrl = "File/images/" + imageUrl; register.setImageUrl(relativeUrl); } return "updateRSuccess"; }
/** * 对教师信息的修改,可以是教师本身或者管理员 * * @return */ public String updateT() { init(); String teacherId = request.getParameter("teacherId"); // 从请求参数过来的是老师更改 if (teacherId == null) { teacherId = request.getSession().getAttribute("USER_ID").toString(); // 从session获得的是老师更改的 } Teacher teacher = personService.getTeacher(teacherId); String imageUrl = teacher.getPictureUrl(); // 服务器绝对地址 if (imageUrl != null) { oldPicturePath = imageUrl; // 保存一个地址,用于和更新后的比较是否有变化,有变化就删除原来的图片 imageUrl = imageUrl.substring(imageUrl.lastIndexOf("\\") + 1); String relativeUrl = "File/images/" + imageUrl; // 浏览器相对地址 teacher.setPictureUrl(relativeUrl); } request.setAttribute("teacher", teacher); return "updateTSuccess"; }
/** * 对学生信息的修改,可以是学生本身或者管理员 * * @return * @throws Exception */ public String updateS() throws Exception { init(); String studentId = request.getParameter("studentId"); // 从请求参数过来的是老师更改 if (studentId == null) { studentId = request.getSession().getAttribute("USER_ID").toString(); // 从session获得的是学生更改的 } Student student = personService.getStudent(studentId); String imageUrl = student.getImageUrl(); if (imageUrl != null) { oldPicturePath = imageUrl; imageUrl = imageUrl.substring(imageUrl.lastIndexOf("\\") + 1); String relativeUrl = "File/images/" + imageUrl; student.setImageUrl(relativeUrl); } request.setAttribute("student", student); return "updateSSuccess"; }