81,095
社区成员
发帖
与我相关
我的任务
分享
public List getPatientsListByUid(final VPlist vplist,final int pageNo,final int pageSize,final int ulevel) {
try {
if (vplist!=null && vplist.getUid()>0) {
List list = getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
//String hql = "from TPatients where uid=? order by pstate,pctime";
String hql = null;
Query query =null;
if(ulevel==2){
hql = "from VPlist where uid=? order by pstate,pctime";
query = session.createQuery(hql);
query.setInteger(0, vplist.getUid());
}else if(ulevel==9){
hql = "from VPlist where hunitid=? and pstate = 2 order by pstate,pctime";
query = session.createQuery(hql);
query.setInteger(0, vplist.getHunitid());
}else if(ulevel==99){
hql = "from VPlist where pstate = 2 order by pstate,pctime";
query = session.createQuery(hql);
}
int first = pageSize*(pageNo-1);
query.setFirstResult(first);
query.setMaxResults(pageSize);
return query.list();
}
});
return list;
}else {
return null;
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public List getPatientsSearchByPnumber(final int uid,final int ulevel,final int sel_City,final int sel_Hunit,
final int state,final int name_pnumber,final String n_p_value,final int pageSize,final int pageNo){
try{
List list = getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
StringBuffer sb = new StringBuffer("from VPlist where");
if(sel_City>=0){
sb.append(" areaId = "+sel_City+" and");
}if(sel_Hunit>=0){
sb.append(" hunitid = "+sel_Hunit+" and");
}if(state>=0 && ulevel==2){
sb.append(" pstate = "+state+" ");
}if(name_pnumber==1){
sb.append(" pnumber = '"+n_p_value+"' and");
}if(name_pnumber==2){
sb.append(" gsName = '"+n_p_value+"' and");
}if(ulevel==9 || ulevel==99){
sb.append(" pstate = 2 and");
}else{
sb.append(" uid = "+uid);
}
String hql = sb.toString();
System.out.println(hql);
Query query = session.createQuery(hql);
int first = pageSize*(pageNo-1);
query.setFirstResult(first);
query.setMaxResults(pageSize);
return query.list();
}
});
return list;
}catch(Exception e){
e.printStackTrace();
return null;
}
}
public int getPatientsSearchCount(int uid,int ulevel,int sel_City,int sel_Hunit,
int state,int name_pnumber,String n_p_value){
int count = 0;
List list = null;
try {
StringBuffer sb = new StringBuffer("from VPlist where 1=1 ");
if(sel_City>=0){
sb.append(" and areaId = "+sel_City+" ");
}if(sel_Hunit>=0){
sb.append(" and hunitid = "+sel_Hunit+" ");
}if(state>=0 && ulevel==2){
sb.append(" and pstate = "+state+" ");
}if(name_pnumber==1){
sb.append(" and pnumber = '"+n_p_value+"' ");
}if(name_pnumber==2){
sb.append(" and gsName = '"+n_p_value+"' ");
}if(ulevel==9 || ulevel==99){
sb.append(" and pstate = 2 ");
}else{
sb.append(" and uid = "+uid);
}
String hql = sb.toString();
list = getHibernateTemplate().find(hql);
if (list!=null && list.size()>0) {
count = list.size();
}
} catch (Exception e) {
e.printStackTrace();
return 0;
}
return count;
}
List list = getHibernateTemplate().find(hql);
System.out.println(list.size());
这个List就能得到正确的值~!但是query 怎么就得不到呢??