本文实例为大家分享了zTree树形插件异步加载,Struts2框架,供大家参考,具体内容如下
上面呢,是jsp页面的代码,因为是纯插件测试,可以直接复制过去使用的,
action层代码,可以直接复制使用
<div class="jb51code">
<pre class="brush:java;">
//service代码,几本都可以复制使用
package com.jk.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.jk.dao.ZtreeDao;
import com.jk.model.Ztree;
import com.jk.service.ZtreeService;
@Repository("ztreeService")
public class ZtreeServiceImpl implements ZtreeService {
@Autowired
private ZtreeDao ztreeDao;
@Override
public List queryList(Ztree ztree) throws Exception {
String hql=" from Ztree where 1=1 ";
Map<String,Object> params = new HashMap<String,Object>();
//传的对象是否为空,拼接sql+id
if(ztree.getId()!=null){
hql+=" and id = :id ";
params.put("id",ztree.getId());
}
return ztreeDao.queryList(hql,p<a href="https://www.jb51.cc/tag/ara/" target="_blank" class="keywords">ara</a>ms);
}
//递归查询
@Override
public List
String hql=" from Ztree where 1=1 ";
Map<String,Object> params=new HashMap<String,Object>();
if(ztree.getId()==null||ztree.getId().equals("")){
hql+=" and pid is null ";
}else{
hql+= " and pid = :id ";
params.put("id",ztree.getId());
}
List
List
for(Ztree ztree2:queryZtree){
if(queryBoolean(ztree2)){
ztree2.setIsParent("true");
}
list.add(ztree2);
}
return list;
}
//熟悉递归的朋友应该可以看懂,我就不解释了,我也聊不清楚这个递归,不误导了,代码在这,可以复制进去直接运行,
public boolean queryBoolean(Ztree ztree) throws Exception{
boolean flag=false;
String hql= " from Ztree where pid = :id ";
Map<String,Object>();
p<a href="https://www.jb51.cc/tag/ara/" target="_blank" class="keywords">ara</a>ms.put("id",ztree.getId());
List<Ztree> queryZtree = ztreeDao.queryList(hql,p<a href="https://www.jb51.cc/tag/ara/" target="_blank" class="keywords">ara</a>ms);
if(queryZtree!=null&&queryZtree.size()>0){
flag=true;
}
return flag;
}
}