<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();
}
}