/** 保存新增,@Valid标注spirng在绑定对象时自动为我们验证对象属性并存放errors在BindingResult */
 @RequestMapping(method = RequestMethod.POST)
 public ModelAndView create(
     HttpServletRequest request, HttpServletResponse response, LeafInfo leafInfo)
     throws Exception {
   leafInfoManager.save(leafInfo);
   return new ModelAndView(LIST_ACTION);
 }
 /** 保存更新,@Valid标注spirng在绑定对象时自动为我们验证对象属性并存放errors在BindingResult */
 @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
 public String update(
     ModelMap model,
     @PathVariable java.lang.Long id,
     @Valid LeafInfo leafInfo,
     BindingResult errors,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   if (errors.hasErrors()) return "/tree/edit";
   leafInfoManager.update(leafInfo);
   return (LIST_ACTION);
 }
  @SuppressWarnings("unchecked")
  public String loadExtSubsTree(final HttpServletRequest pRequest, LeafInfo leafInfo)
      throws Exception {

    final Long parentID = leafInfo.getLeafParentId();
    final String parentTYPE = leafInfo.getLeafParentType();

    PageRequest pageRequest = bindPageRequest(pRequest, leafInfo, DEFAULT_SORT_COLUMNS);
    pageRequest.setPageSize(1000);

    Page nodesPages = leafInfoManager.findByPageRequest(pageRequest);

    AbstractWebTreeModelCreator treeModelCreator =
        new AbstractWebTreeModelCreator() {
          @Override
          protected Node createNode(Object pUserData, UserDataUncoder pUncoder) {
            LeafInfo leaf = (LeafInfo) pUserData;
            WebTreeDynamicNode result =
                new WebTreeDynamicNode(
                    leaf.getLeafName(), leaf.getLeafType() + "_" + leaf.getLeafId());
            result.setSubTreeURL(
                getUrl(
                    "/tree/"
                        + leaf.getLeafId()
                        + "?"
                        + PARENT_ID
                        + "="
                        + leaf.getLeafId()
                        + "&"
                        + PARENT_TYPE
                        + "="
                        + leaf.getLeafType()
                        + "&random="
                        + Math.random()));

            result.setValue(String.valueOf(leaf.getLeafId()));
            result.setTip(leaf.getLeafName());

            // 台区
            if (SystemConst.TREE_TG.equals(leaf.getLeafType())) {
              result.setIcon(getUrl(TG_IMG));
              result.setAction("javascript:showTg(" + leaf.getLeafId() + ")");
            } else if (SystemConst.TREE_ORG.equals(leaf.getLeafType())) {
              result.setIcon(getUrl(ORG_IMG));
              result.setAction("javascript:showOrg(" + leaf.getLeafId() + ")");
            }

            return result;
          }
        };
    treeModelCreator.init(pRequest);

    TreeModel treeModel =
        treeModelCreator.create(
            nodesPages.getResult(),
            new UserDataUncoder() {

              public Object getParentID(Object arg) throws UncodeException {

                return parentID;
              }

              public Object getID(Object arg) throws UncodeException {
                return ((LeafInfo) arg).getLeafId();
              }
            });

    TreeDirector director = new DefaultTreeDirector();
    director.setComparator(new DefaultNodeComparator());
    WebTreeBuilder treeBuilder = new ExtSubTreeBuilder();
    treeBuilder.init(pRequest);
    director.build(treeModel, treeBuilder);

    String treeScript = treeBuilder.getTreeScript();

    return treeScript;
  }
 /** 编辑 */
 @RequestMapping(value = "/{id}/edit")
 public String edit(ModelMap model, @PathVariable java.lang.Long id) throws Exception {
   LeafInfo leafInfo = (LeafInfo) leafInfoManager.getById(id);
   model.addAttribute("leafInfo", leafInfo);
   return "/tree/edit";
 }