@RequestMapping(value = {"user/reviseApplication", "user/writeApplication"})
 public String writeApplication(
     HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model)
     throws IOException {
   if (session == null || session.getAttribute("userid") == null) {
     response.sendRedirect("");
     return null;
   }
   int sessionId = (Integer) session.getAttribute("userid");
   int itemId = -1;
   int projectId = Integer.parseInt(request.getParameter("pid"));
   model.addAttribute("project", projectService.getProject(projectId));
   if (request.getParameter("iid") != null) {
     itemId = Integer.parseInt(request.getParameter("iid"));
     Application application =
         applicationService.getApplicationFromId(sessionId, projectId, itemId);
     model.addAttribute("amount", application.getAmount());
     model.addAttribute("iid", itemId);
   }
   // 获得这个项目的可以报销的项目List<iid>
   List<Ipmapping> itemIdList = itemService.getIpmapByProjectId(projectId);
   if (itemId != -1) {
     for (Ipmapping ipmapping : itemIdList) {
       if (ipmapping.getId().getItem().getIid() == itemId) {
         model.addAttribute("max", ipmapping.getAmount() / ipmapping.getRate());
         break;
       }
     }
   }
   model.addAttribute("iplist", itemIdList);
   return "user/submitApplication";
 }
  // 处理lead project提交的表单
  @RequestMapping("user/leadProject/submit")
  public String leadProjectSubmit(
      HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model)
      throws IOException {
    if (session == null || session.getAttribute("userid") == null) {
      response.sendRedirect("");
      return null;
    }
    int sessionId = (Integer) session.getAttribute("userid");
    int projectId = Integer.parseInt(request.getParameter("id"));
    List<Ipmapping> ipmappings = itemService.getIpmapByProjectId(projectId);
    model.addAttribute("iplist", ipmappings);
    model.addAttribute("project", projectService.getProject(projectId));
    List<User> userList = userService.getAllUserByRole(User.ROLE_USER);
    // 取掉leader自己
    userList.remove(userService.getUser(sessionId));
    model.addAttribute("userlist", userList);
    int left = Integer.parseInt(request.getParameter("left"));
    if (left < 0) {
      request.setAttribute("message", "your left money is below zero.");
      return "user/leadProject";
    }
    // 获得网页上选中的项,处理
    String[] members = request.getParameterValues("members");
    model.addAttribute("members", members);
    // iid,amount
    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
    for (Ipmapping ipmapping : ipmappings) {
      int iid = ipmapping.getId().getItem().getIid();
      String value = request.getParameter(String.valueOf(iid));
      if (value == null || value.equals("")) {
        request.setAttribute("message", "please complete this page");
        return "user/leadProject";
      }
      int tempAmount = Integer.parseInt(value);
      map.put(iid, tempAmount);
      model.addAttribute(String.valueOf(iid), tempAmount);
    }
    ArrayList<Integer> membersID = new ArrayList<Integer>();
    for (String s : members) {
      int temp = Integer.parseInt(s);
      membersID.add(temp);
    }
    projectService.reviseProject(projectId, membersID, map);

    // 表单(修改project)处理成功,则重定向到userhome
    request.setAttribute("title", "project completed!");
    request.setAttribute("message", "You have successfully assign the project");
    request.setAttribute("redirect", "userhome");
    return "template/message";
  }
  @RequestMapping("user/leadProject")
  public String leadProject(
      HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model)
      throws IOException {
    if (session == null || session.getAttribute("userid") == null) {
      response.sendRedirect("");
      return null;
    }
    int sessionId = (Integer) session.getAttribute("userid");
    int projectId = Integer.parseInt(request.getParameter("id"));

    List<Ipmapping> ipmappings = itemService.getIpmapByProjectId(projectId);
    model.addAttribute("iplist", ipmappings);
    model.addAttribute("project", projectService.getProject(projectId));

    List<User> userList = userService.getAllUserByRole(User.ROLE_USER);
    // 添加成员需要把主持人给移除
    User leader = null;
    for (User user : userList) {
      if (user.getUid() == sessionId) {
        leader = user;
        break;
      }
    }
    userList.remove(leader);
    model.addAttribute("userlist", userList);
    ArrayList<String> temp = new ArrayList<String>();
    ArrayList<Integer> members = projectService.getMembersFromProjectID(projectId);
    if (members != null && members.size() != 0) {
      for (Integer integer : members) {
        temp.add(String.valueOf(integer));
      }
      model.addAttribute("members", temp.toArray(new String[temp.size()]));
    }
    return "user/leadProject";
  }