String strSqlInfo="select u from Usertable u where 1=1 ";
String sqlParamName="";
String sqlParamValue="";
String contactSql="";
if(username!=null && !"".equals(username)){
contactSql+=" and u.username like :username";
sqlParamName="username";
sqlParamValue="%"+username+"%";
}
if(uname!=null && !"".equals(uname)){
contactSql+=" and u.uname like :uname";
if(sqlParamName.length()>0){
sqlParamName+=",";
sqlParamValue+=",";
}
sqlParamName+="uname";
sqlParamValue+="%"+uname+"%";
}
if(sex!=null && !"".equals(sex)){
contactSql+=" and u.sex=:sex ";
if(sqlParamName.length()>0){
sqlParamName+=",";
sqlParamValue+=",";
}
sqlParamName+="sex";
sqlParamValue+=sex;
}
String[] strName=null;
Object[] objValue=null;
if(!"".equals(sqlParamName) && !"".equals(sqlParamValue)){ //判断是否有查询条件
strName=sqlParamName.split(",");
objValue=sqlParamValue.split(",");
strSqlInfo+=contactSql;
}
Query q = session.createQuery(p.getListSQL());
if(str!=null){
for (int i = 0; i < str.length; i++) {
q.setParameter(str[i], ob2[i]);
}
}
q.setFirstResult((p.getPage() - 1) * p.getPageSize());
q.setMaxResults(p.getPageSize());
return q.list();