Exemplo n.º 1
0
  @RequestMapping(value = "add", method = RequestMethod.POST)
  public String add(
      String name,
      String email,
      String tel,
      String cid,
      String password,
      MultipartFile photofile,
      Model model)
      throws Exception {

    String newFileName = null;

    if (photofile.getSize() > 0) {
      newFileName = MultipartHelper.generateFilename(photofile.getOriginalFilename());
      File attachfile = new File(servletContext.getRealPath(SAVED_DIR) + "/" + newFileName);
      photofile.transferTo(attachfile);

      makeThumbnailImage(
          servletContext.getRealPath(SAVED_DIR) + "/" + newFileName,
          servletContext.getRealPath(SAVED_DIR) + "/s-" + newFileName + ".png");
    }

    Student student = new Student();
    student.setName(name);
    student.setEmail(email);
    student.setTel(tel);
    student.setCid(cid);
    student.setPassword(password);
    student.setPhoto(newFileName);

    studentDao.insert(student);

    return "redirect:list.do";
  }
Exemplo n.º 2
0
  @RequestMapping("detail")
  public String detail(String email, Model model) throws Exception {

    Student student = studentDao.selectOne(email);
    model.addAttribute("student", student);

    return "student/StudentDetail";
  }
Exemplo n.º 3
0
  @RequestMapping("delete")
  public String delete(String email, Model model) throws Exception {

    if (studentDao.delete(email) <= 0) {
      model.addAttribute("errorCode", "401");
      return "/student/StudentAuthError.jsp";
    }
    return "redirect:list.do";
  }
Exemplo n.º 4
0
  @Override
  public void service(HashMap<String, Object> params) {
    PrintStream out = (PrintStream) params.get("out");

    out.printf("%-3s %-5s %-17s %-13s %-7s\n", "No", "Name", "E-Mail", "Tel", "ClassID");

    for (Student student : studentDao.selectList()) {
      out.printf(
          "%3d %-5s %-17s %-13s %7s\n",
          student.getNo(),
          student.getName(),
          student.getEmail(),
          student.getTel(),
          student.getCid());
    }
  }
Exemplo n.º 5
0
  @RequestMapping("update")
  public String update(
      String name,
      String email,
      String tel,
      String cid,
      String photo,
      MultipartFile photofile,
      Model model)
      throws Exception {

    String newFileName = null;

    if (photofile.getSize() > 0) {
      newFileName = MultipartHelper.generateFilename(photofile.getOriginalFilename());
      File attachfile = new File(servletContext.getRealPath(SAVED_DIR) + "/" + newFileName);
      photofile.transferTo(attachfile);

      makeThumbnailImage(
          servletContext.getRealPath(SAVED_DIR) + "/" + newFileName,
          servletContext.getRealPath(SAVED_DIR) + "/s-" + newFileName + ".png");
    }

    Student student = new Student();
    student.setName(name);
    student.setEmail(email);
    student.setTel(tel);
    student.setCid(cid);

    if (newFileName != null) {
      student.setPhoto(newFileName);
    } else if (newFileName == null && photo.length() > 0) {
      student.setPhoto(photo);
    }

    if (studentDao.update(student) <= 0) {
      model.addAttribute("errorCode", "401");
      return "student/StudentAuthError";
    }

    return "redirect:list.do";
  }
Exemplo n.º 6
0
  @RequestMapping("list")
  public String list(
      @RequestParam(defaultValue = "1") int pageNo,
      @RequestParam(defaultValue = "10") int pageSize,
      @RequestParam(defaultValue = "email") String keyword,
      @RequestParam(defaultValue = "asc") String align,
      Model model)
      throws Exception {

    HashMap<String, Object> paramMap = new HashMap<>();
    paramMap.put("startIndex", (pageNo - 1) * pageSize);
    paramMap.put("length", pageSize);
    paramMap.put("keyword", keyword);
    paramMap.put("align", align);

    List<Student> students = studentDao.selectList(paramMap);

    model.addAttribute("students", students);

    return "student/StudentList";
  }