查询当前节点的所有子字节:
@SuppressWarnings("unchecked")
public List<String> findAllChildColumnIdById(long id) throws Exception {
return em
.createNativeQuery(
"select to_char(i.id) FROM columns i start with i.id=:id connect by PRIOR i.id=i.f_parentId order by i.id asc")
.setParameter("id", id).getResultList();
}
当前节点找根节点
public String findRootIdByColumnId(long id) throws Exception {
return (String)em
.createNativeQuery(
"select to_char(i.id) FROM columns i where i.f_parentId=0 start with i.id=:id connect by PRIOR i.f_parentId=i.id ")
.setParameter("id", id).getSingleResult();
}
根据根节点找所有节点:
@SuppressWarnings("unchecked")
public List<InfoColumn> findAllChildColumnIdByRootId(long id) throws Exception {
List objects =em
.createNativeQuery(
"select i.id,i.f_name,i.f_parentId FROM columns i start with i.id=:id connect by PRIOR i.id=i.f_parentId order by i.id asc")
.setParameter("id", id).getResultList();
if(objects!=null&&objects.size()>0){
List<InfoColumn> infocs = new ArrayList<InfoColumn>();
for (Object o : objects) {
InfoColumn i = new InfoColumn();
Object[] os = (Object[]) o;
i.setId(Long.parseLong(os[0].toString()));
i.setName(os[1] != null ? os[1].toString() : "");
i.setParentId(Long.parseLong(os[2].toString()));
infocs.add(i);
}
return infocs;
}else{
return null;
}
}
多表查询:
@SuppressWarnings("unchecked")
public List<Info> findInfoByColumnIds(List<String> ids, int pageindex,
int max) throws Exception {
String QL = "select distinct o.id,o.title,o.path,o.updateDate FROM Info o,InfoColumn i where o in elements(i.infos) ";
StringBuffer temp = new StringBuffer();
if (ids != null && ids.size() > 0) {
for (String id : ids) {
temp.append(",");
temp.append(id);
}
}
List objects= em.createQuery(QL + " and i.id in("
+ temp.substring(1).toString()
+ ") and (o.state=2 or o.state=3) order by o.updateDate desc").setFirstResult(
pageindex).setMaxResults(max).getResultList();
if(objects!=null&&objects.size()>0){
List<Info> infos = new ArrayList<Info>();
for (Object o : objects) {
Info i = new Info();
Object[] os = (Object[]) o;
i.setId(Long.parseLong(os[0].toString()));
i.setTitle(os[1] != null ? os[1].toString() : "");
i.setPath(os[2] != null ? os[2].toString() : "");
infos.add(i);
}
return infos;
}else{
return null;
}
}
分享到:
相关推荐
mysql 递归查询 树型结构 代码逻辑
java递归树型结构通用数据库
利用树型结构进行数据组织, 层次清晰、操作方便、用途广泛。介绍了一种基于 VS.NET 技术设计实现的大数据量树型结 构数据的快速加载方法, 通过一种改进的基于广度优先的算法, 将树型数据按照一定的层次和需要, 分散...
springJpa单标递归树形结构
非常不错的js代码 简单 易用 而且美观 如果你还对js生成像windows文件夹结构的树型结构苦恼的话 就来下载吧
树型结构是一类重要的非线性数据结构,而二叉树是最为重要,最为常用的类型。树结构在客观世界中广泛存在,如人类社会的族谱和各种社会组织机构都可以用树来形象表示。树在计算机领域中也得到广泛应用,如在编译程序...
请参考数据库显示,看数据库内内容.这里仅仅给出了使用数据库中的数据创建树的示例,至于向数据库中增加数据大家可以摸索尝试,这里就不再给出。
利用树型结构本身就是一种递归定义的特点,引入树型结构对递归问题进行分析。
我们经常遇到树型结构,把它们显示在一个类似TreeView控件上的情况。这时我们可以使用Recursive Common Table Expressions(CTE)实现
这是一个Delphi中用递归读取数据库数据创建树的示例程序----Copyright by 飘摇客 2002,适合初学者参考。
#资源达人分享计划#
#资源达人分享计划#
JSP_遍历树(递归),JSP_遍历树(递归)
实验项目:树型结构的建立、遍历和应用 实验题目:二叉树存储结构的建立、遍历和应用 实验内容: 树型结构的遍历是树型结构算法的基础,本实验要求编写程序演示二叉树 的存储结构的建立方法、遍历过程以及应用。 ...
我现在的JSP论坛采用的也是当中的一种:不用递归实现树型结构的算法,现在我将论坛树型结构的具体算法和大家介绍一下,和大家一起交流。 1。演示表的结构: 表名:mybbslist 字段 数据类型 说明 BBSID 自动...
java写的从数据库中提取数据,用变量创建树型结构
public static void TreeBuilder(List<T> all, T currentParentItem, long? parentId = null, string idProperty = "Id", string parentIdProperty = "ParentId", string childrenProperty = "ChildrenCollection...
//查询一张表 返回dataset 类型 (陆续推出其他类型绑定 //注意: 数据表格式必须是 递归类型 //比如: //ID Pid Name //1 0 a //2 0 b //3 0 c //4 0 d //5 1 e //id为5的 是ID为1的子类... //6 1 f //同上 ...
实现递归查询(树形结构) 2. 可以在一个语句中多次引用公用表表达式,使其更加简洁 二、非递归的公共表达式 可以是定义列或自动列和select into 效果差不多 --指定列 with withTmp1 (code,cName) as ( select ...