@RequestMapping(
     value = {"/add"},
     method = RequestMethod.POST)
 @ResponseBody
 public EventModel add(HttpServletRequest request, @ModelAttribute EventModel em) {
   Event event = new Event();
   event.setUid(em.getUid());
   // 格式:"2015-07-02 8:0:0"
   event.setStart(DataUtil.StrToDate(em.getStart()));
   event.setEnd(DataUtil.StrToDate(em.getEnd()));
   int eventId = eventService.add(event);
   em.setId(eventId);
   return em;
 }
 @RequestMapping(
     value = {"/delete/{id}"},
     method = RequestMethod.POST)
 @ResponseBody
 public boolean delete(HttpServletRequest request, @PathVariable(value = "id") int id) {
   try {
     eventService.delete(id);
     ;
     return true;
   } catch (Exception e) {
     e.printStackTrace();
   }
   return false;
 }
 @RequestMapping(
     value = {"/update"},
     method = RequestMethod.POST)
 @ResponseBody
 public boolean update(HttpServletRequest request, @ModelAttribute EventModel em) {
   try {
     Event event = new Event();
     event.setId(em.getId());
     event.setUid(em.getUid());
     // 格式:"2015-07-02 8:0:0"
     event.setStart(DataUtil.StrToDate(em.getStart()));
     event.setEnd(DataUtil.StrToDate(em.getEnd()));
     eventService.update(event);
     return true;
   } catch (Exception e) {
     e.printStackTrace();
   }
   return false;
 }
  @RequestMapping(
      value = {"/list"},
      method = RequestMethod.GET)
  @ResponseBody
  public List<EventModel> list(HttpServletRequest request) {
    List<Event> events = eventService.list();
    List<EventModel> ems = new ArrayList<>();
    for (Event e : events) {
      EventModel em = new EventModel();
      em.setId(e.getId());
      em.setUid(e.getUid());
      User u = userService.getUserById(e.getUid());
      if (u == null) {
        em.setTitle("");
      } else {
        em.setTitle(u.getUsername());
      }
      em.setStart(DataUtil.DateToStr(e.getStart()));
      em.setEnd(DataUtil.DateToStr(e.getEnd()));
      ems.add(em);
    }

    return ems;
  }