コード例 #1
0
  @AuthPassport
  @RequestMapping(
      value = "/add/{id}",
      method = {RequestMethod.GET})
  public String add(
      HttpServletRequest request, Model model, @PathVariable(value = "id") Integer id) {
    if (!model.containsAttribute("contentModel")) {
      AuthorityEditModel authorityEditModel = new AuthorityEditModel();
      authorityEditModel.setParentId(id);
      model.addAttribute("contentModel", authorityEditModel);
    }

    List<TreeModel> treeModels;
    String expanded = ServletRequestUtils.getStringParameter(request, "expanded", null);
    if (id != null && id > 0) {
      List<TreeModel> children =
          TreeModelExtension.ToTreeModels(
              authorityService.listChain(), id, 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";
  }
コード例 #2
0
  @AuthPassport
  @RequestMapping(
      value = "/chain",
      method = {RequestMethod.GET})
  public String chain(HttpServletRequest request, Model model) {
    if (!model.containsAttribute("contentModel")) {
      String expanded = ServletRequestUtils.getStringParameter(request, "expanded", null);
      List<TreeModel> children =
          TreeModelExtension.ToTreeModels(
              authorityService.listChain(), null, null, StringHelper.toIntegerList(expanded, ","));
      List<TreeModel> treeModels =
          new ArrayList<TreeModel>(
              Arrays.asList(new TreeModel("0", "0", "根节点", false, false, false, children)));

      String jsonString = JSONArray.fromObject(treeModels, new JsonConfig()).toString();
      model.addAttribute("contentModel", jsonString);
    }

    model.addAttribute("requestUrl", request.getServletPath());
    model.addAttribute("requestQuery", request.getQueryString());

    return "authority/chain";
  }