/** 批量删除 */ @RequestMapping(method = RequestMethod.DELETE) public String batchDelete(ModelMap model, @RequestParam("items") java.lang.Integer[] items) { for (int i = 0; i < items.length; i++) { permissionGroupManager.removeById(items[i]); } Flash.current().success(DELETE_SUCCESS); return LIST_ACTION; }
/** 保存新增,@Valid标注spirng在绑定对象时自动为我们验证对象属性并存放errors在BindingResult */ @RequestMapping(method = RequestMethod.POST) public String create( ModelMap model, @Valid PermissionGroup permissionGroup, BindingResult errors, HttpServletRequest request, HttpServletResponse response) throws Exception { if (errors.hasErrors()) { return "/permissiongroup/new"; } permissionGroupManager.save(permissionGroup); Flash.current().success(CREATED_SUCCESS); // 存放在Flash中的数据,在下一次http请求中仍然可以读取数据,error()用于显示错误消息 return LIST_ACTION; }
/** 保存更新,@Valid标注spirng在绑定对象时自动为我们验证对象属性并存放errors在BindingResult */ @RequestMapping(value = "/{id}", method = RequestMethod.PUT) public String update( ModelMap model, @PathVariable java.lang.Integer id, @Valid PermissionGroup permissionGroup, BindingResult errors, HttpServletRequest request, HttpServletResponse response) throws Exception { if (errors.hasErrors()) { return "/permissiongroup/edit"; } permissionGroupManager.update(permissionGroup); Flash.current().success(UPDATE_SUCCESS); return LIST_ACTION; }
/** 显示 */ @RequestMapping(value = "/{id}") public String show(ModelMap model, @PathVariable java.lang.Integer id) throws Exception { PermissionGroup permissionGroup = (PermissionGroup) permissionGroupManager.getById(id); model.addAttribute("permissionGroup", permissionGroup); return "/permissiongroup/show"; }
/** 删除 */ @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) public String delete(ModelMap model, @PathVariable java.lang.Integer id) { permissionGroupManager.removeById(id); Flash.current().success(DELETE_SUCCESS); return LIST_ACTION; }