第一步
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;
}