コード例 #1
0
  @AuthPassport
  @RequestMapping(
      value = "/add/{id}",
      method = {RequestMethod.POST})
  public String add(
      HttpServletRequest request,
      Model model,
      @Valid @ModelAttribute("contentModel") AuthorityEditModel editModel,
      @PathVariable(value = "id") Integer id,
      BindingResult result)
      throws EntityOperateException, ValidatException {
    if (result.hasErrors()) return add(request, model, id);

    String returnUrl = ServletRequestUtils.getStringParameter(request, "returnUrl", null);
    Authority authority = AuthorityModelExtension.toAuthority(editModel);
    authorityService.save(authority);
    if (returnUrl == null) returnUrl = "authority/chain";
    return "redirect:" + returnUrl;
  }
コード例 #2
0
  @AuthPassport
  @RequestMapping(
      value = "/edit/{id}",
      method = {RequestMethod.GET})
  public String edit(
      HttpServletRequest request, Model model, @PathVariable(value = "id") Integer id)
      throws ValidatException {
    if (!model.containsAttribute("contentModel")) {
      AuthorityEditModel authorityEditModel =
          AuthorityModelExtension.toAuthorityEditModel(authorityService.get(id));
      model.addAttribute("contentModel", authorityEditModel);
    }

    List<TreeModel> treeModels;
    AuthorityEditModel editModel = (AuthorityEditModel) model.asMap().get("contentModel");
    String expanded = ServletRequestUtils.getStringParameter(request, "expanded", null);
    if (editModel.getParentId() != null && editModel.getParentId() > 0) {
      List<TreeModel> children =
          TreeModelExtension.ToTreeModels(
              authorityService.listChain(),
              editModel.getParentId(),
              null,
              StringHelper.toIntegerList(expanded, ","));
      treeModels =
          new ArrayList<TreeModel>(
              Arrays.asList(new TreeModel("0", "0", "根节点", false, false, false, children)));
    } else {
      List<TreeModel> children =
          TreeModelExtension.ToTreeModels(
              authorityService.listChain(), null, null, StringHelper.toIntegerList(expanded, ","));
      treeModels =
          new ArrayList<TreeModel>(
              Arrays.asList(new TreeModel("0", "0", "根节点", false, true, false, children)));
    }
    model.addAttribute(
        treeDataSourceName, JSONArray.fromObject(treeModels, new JsonConfig()).toString());

    return "authority/edit";
  }