java 实现树形结构返回_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > java 实现树形结构返回

java 实现树形结构返回

 2013/10/8 13:29:47  annan211  程序员俱乐部  我要评论(0)
  • 摘要:第一步getResourceFromTresource(find(resources))第二步privateList<Tresources>find(Resourcesresources){Stringhql="fromTresourcestwhere1=1andt.tres=NULL";List<Object>values=newArrayList<Object>();hql=addWhere(resources,hql,values);if
  • 标签:实现 Java
第一步
class="java" name="code">
getResourceFromTresource(find(resources))


第二步
private List<Tresources> find(Resources resources) {
		String hql = "from Tresources t where 1=1 and t.tres = NULL";

		List<Object> values = new ArrayList<Object>();
		hql = addWhere(resources, hql, values);

		if (resources.getSort() != null && resources.getOrder() != null) {
			hql += " order by " + " " + resources.getOrder()+" "+ resources.getSort() ;
		}
		return resourceDao.find(hql, resources.getPage(), resources.getRows(), values);
	}
	private String addWhere(Resources resources, String hql, List<Object> values) {
		return hql;
	}

public List<T> find(String hql, int page, int rows, List<Object> param) {
		Query q = this.getCurrentSession().createQuery(hql);
		if (param != null && param.size() > 0) {
			for (int i = 0; i < param.size(); i++) {
				q.setParameter(i, param.get(i));
			}
		}
		return q.setFirstResult((page - 1) * rows).setMaxResults(rows).list();
	}
private List<Resources> getResourceFromTresource(List<Tresources> tresources) {
		List<Resources> resources = new ArrayList<Resources>();
		if (tresources != null && tresources.size() > 0) {
			for (Tresources tu : tresources) {
				String resourceNames = "";
				resourceNames += ","+tu.getName();
				Resources u = new Resources();
				BeanUtils.copyProperties(tu, u);
				if(tu.getTresources().size()>0){
					Set<Tresources> tres = tu.getTresources();
					for (Tresources tre2 : tres) {
						resourceNames += ","+tre2.getName();
					}
				}
				if(tu.getTres()!=null){
					u.setpId(tu.getTres().getId());
					u.setPname(tu.getTres().getName());
				}
				u.setResourceNames(resourceNames);
				resources.add(u);
			}
		}
		return resources;
	}
发表评论
用户名: 匿名