jeecg中的树形控件demo

1.comboTree控件

       1.页面方法:

            <t:comboTree url="jeecgFormDemoController.do?getComboTreeData" value="402880e447e99cf10147e9a03b320003" name="depid" id="depid" width="200"></t:comboTree>

  2.controller方法:

  

    @RequestMapping(params = "getComboTreeData")
    @ResponseBody
    public List<ComboTree> getComboTreeData(HttpServletRequest request, ComboTree comboTree) {
        CriteriaQuery cq = new CriteriaQuery(TSDepart.class);
          if (comboTree.getId() != null) {
            cq.eq("TSPDepart.id", comboTree.getId());
                        }
          if (comboTree.getId() == null) {
            cq.isNull("TSPDepart");
                        }
              cq.add();
          List<TSDepart> demoList = systemService.getListByCriteriaQuery(cq, false);
          List<ComboTree> comboTrees = new ArrayList<ComboTree>();
          ComboTreeModel comboTreeModel = new ComboTreeModel("id", "departname", "TSDeparts");
              comboTrees = systemService.ComboTree(demoList, comboTreeModel, null, false);
                  return comboTrees;
                          }

2.ztree 控件

    1.页面方法:

        <t:selectZTree id="citySel" url="jeecgFormDemoController.do?getTreeData" windowWidth="400px"></t:selectZTree> 

    2.controller层方法

        

@RequestMapping(params="getTreeData",method ={RequestMethod.GET, RequestMethod.POST})
@ResponseBody
public AjaxJson getTreeData(TSDepart depatr,HttpServletResponse response,HttpServletRequest request ){
AjaxJson j = new AjaxJson();
try{
List<TSDepart> depatrList = new ArrayList<TSDepart>();
StringBuffer hql = new StringBuffer(" from TSDepart t");
//hql.append(" and (parent.id is null or parent.id='')");
depatrList = this.systemService.findHql(hql.toString());
List<Map<String,Object>> dataList = new ArrayList<Map<String,Object>>();
Map<String,Object> map = null;
for (TSDepart tsdepart : depatrList) {
String sqls = null;
Object[] paramss = null;
map = new HashMap<String,Object>();
map.put("id", tsdepart.getId());
map.put("name", tsdepart.getDepartname());
if (tsdepart.getTSPDepart() != null) {
map.put("pId", tsdepart.getTSPDepart().getId());
map.put("open",false);
}else {
map.put("pId", "1");
map.put("open",false);
}
sqls = "select count(1) from t_s_depart t where t.parentdepartid = ?";
paramss = new Object[]{tsdepart.getId()};
long counts = this.systemService.getCountForJdbcParam(sqls, paramss);
if(counts>0){
dataList.add(map);
}else{
TSDepart de = this.systemService.get(TSDepart.class, tsdepart.getId());
if (de != null) {
map.put("id", de.getId());
map.put("name", de.getDepartname());
if(tsdepart.getTSPDepart()!=null){
map.put("pId", tsdepart.getTSPDepart().getId());
map.put("open",false);
}else{
map.put("pId", "1");
map.put("open",false);
}
dataList.add(map);
}else{
map.put("open",false);
dataList.add(map);
}
}
}
j.setObj(dataList);
}catch(Exception e){
e.printStackTrace();
}
return j;
}

 

        

          

        

        

        

      

          

      

            

原文地址:https://www.cnblogs.com/xujiating/p/7573251.html