对hibernate不太熟悉,不会转换为原生sql,代码如下,我要把sql改为select u.loginname,u.username from Organization a,Sam_Taxempcode u where a.DistrictNumber=u.district_id 要怎么做
public PagingResult<UserInfo> finduser(UserCond qry, PagingParam pp) {
logger.debug("call findusers()");
String loginname = null;
String username=null;
String district="";
if ( qry != null ){
loginname = qry.getLoginname().trim();
username=qry.getUsername().trim();
district=String.valueOf(qry.getDistrict());
}
if ( pp == null )
pp = new PagingParam();
int end = pp.getStart() + pp.getLimit();
List params = new ArrayList();
String orderBy = " order by u.loginname";
String sql = "select new cn.net.tongfang.framework.security.bo.UserInfo(u) from SamTaxempcode u ";
StringBuffer hql = new StringBuffer(sql);
StringBuffer cond = new StringBuffer();
if ( loginname != null && ! loginname.trim().equals("")) {
cond.append( " and u.loginname like ? " );
params.add("%" + loginname.trim() + "%");
}
if ( username !=null && ! username.trim().equals("")){
cond.append(" and u.username like ? ");
params.add("%" + username.trim() + "%");
}
if(district !=null && ! district.trim().equals("")){
cond.append(" and a.id= ? ");
params.add(district);
}
if ( params.size() > 0 ) {
hql.append(" where 1=1 ").append( cond );
//hql.append(" where 1=1 a.DistrictNumber=u.district_id ").append( cond );
}
hql.append( orderBy );
List list;
if ( params.size() > 0 ) {
list = getHibernateTemplate().find(hql.toString(), params.toArray());
} else {
list =
getHibernateTemplate().find(hql.toString());
}
end = (end < list.size()) ? end : list.size();
List<UserInfo> result = list.subList(pp.getStart(), end);
return new PagingResult<UserInfo>(list.size(), result);
}
添加回答
举报
0/150
提交
取消