/** * 添加一个学生信息 * * @return * @throws Exception */ public String addS() throws Exception { init(); if (pictureUpload() != null) { student.setImageUrl(pictureUpload()); } personService.saveStudent(student); request.setAttribute("SUCCESS", "添加学生成功"); return "addSuccess"; }
/** * 处理学生信息的修改 * * @return * @throws Exception */ public String updateSDeal() throws Exception { init(); if (pictureUpload() != null) { student.setImageUrl(pictureUpload()); if (oldPicturePath != null) { // 设置了新的图片就删除原来的图片 File file = new File(oldPicturePath); if (file.exists()) { file.delete(); } } } personService.updateStudent(student); response.getWriter().write("<script type='text/javascript'> alert('修改学生信息成功')</script>"); response.flushBuffer(); response.getWriter().close(); return NONE; }
/** * 对学生信息的修改,可以是学生本身或者管理员 * * @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"; }