hibnernate 将sql结果集封装为实体对象

来源:互联网 发布:淘宝卖家花呗支付 编辑:程序博客网 时间:2024/05/14 09:21
<pre name="code" class="java">
一、第一种:
public List<AcrossDeptAuthorization> findByInfoClass(int page,int rows,String infoClass,int userId) {
if (userId==1){
String hql = "select c.* from cxzjg_across_dept_auth c join auth_dept_user a on a.auth_id=c.id where 1=1";
if (infoClass!=null && infoClass.trim().length()>0){
hql +=" and c.info_Class_Name like '%"+infoClass+"%'";
}
Query query = getSession().createSQLQuery(hql)

.addEntity("c",AcrossDeptAuthorization.class);
query.setFirstResult((page-1)*rows);
query.setMaxResults(rows);

return query.list();
}else{
String sql = "select c.* from cxzjg_across_dept_auth c join auth_dept_user a on a.auth_id=c.id where 1=1";
if (infoClass!=null && infoClass.trim().length()>0){
sql +=" and c.info_Class_Name like '%"+infoClass+"%'";
}
if (userId!=0){
sql+=" and a.user_Id="+userId;
}
Query query = getSession().createSQLQuery(sql)
.addEntity("c",AcrossDeptAuthorization.class);
query.setFirstResult((page-1)*rows);
query.setMaxResults(rows);
return query.list();

}


}
                                             
0 0
原创粉丝点击