예제 #1
0
 /** 批量删除 */
 @RequestMapping(method = RequestMethod.DELETE)
 public String batchDelete(ModelMap model, @RequestParam("items") java.lang.Long[] items) {
   for (int i = 0; i < items.length; i++) {
     commentManager.removeById(items[i]);
   }
   Flash.current().success(DELETE_SUCCESS);
   return LIST_ACTION;
 }
예제 #2
0
  /** 保存新增,@Valid标注spirng在绑定对象时自动为我们验证对象属性并存放errors在BindingResult */
  @RequestMapping(method = RequestMethod.POST)
  public String create(
      ModelMap model,
      @Valid Comment comment,
      BindingResult errors,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    if (errors.hasErrors()) {
      return "/jtzs/comment/new";
    }

    commentManager.save(comment);
    Flash.current().success(CREATED_SUCCESS); // 存放在Flash中的数据,在下一次http请求中仍然可以读取数据,error()用于显示错误消息
    return LIST_ACTION;
  }
예제 #3
0
  /** 保存更新,@Valid标注spirng在绑定对象时自动为我们验证对象属性并存放errors在BindingResult */
  @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
  public String update(
      ModelMap model,
      @PathVariable java.lang.Long id,
      @Valid Comment comment,
      BindingResult errors,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    if (errors.hasErrors()) {
      return "/jtzs/comment/edit";
    }

    commentManager.update(comment);
    Flash.current().success(UPDATE_SUCCESS);
    return LIST_ACTION;
  }
예제 #4
0
 /** 删除 */
 @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
 public String delete(ModelMap model, @PathVariable java.lang.Long id) {
   commentManager.removeById(id);
   Flash.current().success(DELETE_SUCCESS);
   return LIST_ACTION;
 }
예제 #5
0
 /** 编辑 */
 @RequestMapping(value = "/{id}/edit")
 public String edit(ModelMap model, @PathVariable java.lang.Long id) throws Exception {
   Comment comment = (Comment) commentManager.getById(id);
   model.addAttribute("comment", comment);
   return "/jtzs/comment/edit";
 }