コード例 #1
0
 @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;
 }
コード例 #2
0
  @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;
  }