ssh框架分页查询,有分页类并且作为查询的参数,代码该如何去实现,请各位朋友帮忙解决一下,非常感谢
publicList<IDCCustomer>findCustomerList(Integercustomerid,Stringcustomername,Stringcu...
public List<IDCCustomer> findCustomerList(Integer customerid,String customername,String customertype,PageHolder pageHolder) {
String hql="from IDCCustomer ic where 1=1 ";
if(customerid !=0 &&!customerid.equals("")){
hql += " and ic.customerid="+customerid;
}
if(customername !=null && !customername.equals("")){
hql += " and ic.customername like '%"+customername+"%'";
}
if(customertype !=null && !customertype.equals("")){
hql += " and ic.customertype like '%"+customertype+"%'";
}
if(pageHolder !=null){
Query query = this.getSession().createQuery(hql);
query.setFirstResult(pageHolder.getFirstIndex());
query.setMaxResults(pageHolder.getPageSize());
if(pageHolder.isGetCount()){
pageHolder.setResultSize((int)this.getCount2(hql));
}
// Iterator it = query.list().iterator();
// while(it.hasNext()){
// Object[] row = (Object[])it.next();
// IDCCustomer idc=new IDCCustomer();
// }
}
return this.getHibernateTemplate().find(hql); 展开
String hql="from IDCCustomer ic where 1=1 ";
if(customerid !=0 &&!customerid.equals("")){
hql += " and ic.customerid="+customerid;
}
if(customername !=null && !customername.equals("")){
hql += " and ic.customername like '%"+customername+"%'";
}
if(customertype !=null && !customertype.equals("")){
hql += " and ic.customertype like '%"+customertype+"%'";
}
if(pageHolder !=null){
Query query = this.getSession().createQuery(hql);
query.setFirstResult(pageHolder.getFirstIndex());
query.setMaxResults(pageHolder.getPageSize());
if(pageHolder.isGetCount()){
pageHolder.setResultSize((int)this.getCount2(hql));
}
// Iterator it = query.list().iterator();
// while(it.hasNext()){
// Object[] row = (Object[])it.next();
// IDCCustomer idc=new IDCCustomer();
// }
}
return this.getHibernateTemplate().find(hql); 展开
1个回答
2013-12-02
展开全部
public List<IDCCustomer> findCustomerList(CustomerVo customerVo){
StringBuffer hql=new StringBuffer("rom IDCCustomer ic where 1=1 ");
List list=new ArrayList();
if(customerVo|=null){
if(customerVo.getCustomerid!=null&&"".equals(customerVo.getCustomerid) ){
hql.append(" and ic.customerid=:customerid");
}
if(customerVo.getCustomername !=null&&"".equals(customerVo.getCustomername ) ){
hql.append(" and ic.customername =:customername ");
}
//customerVo.orderByStr 保存内容格式 :"customername desc/customername asc ......"
if(customerVo.getOrderByStr !=null&&"".equals(customerVo.getOrderByStr ) ){
hql.append(" order by :orderByStr customerid desc");
}
}
Query query = this.getSession().createQuery(hql);
query.setFirstResult(pageHolder.getFirstIndex());
query.setMaxResults(pageHolder.getPageSize());
if(customerVo|=null){
if(customerVo.getCustomerid!=null&&"".equals(customerVo.getCustomerid) ){
query.setParamter("customerid",customerid);
}
if(customerVo.getCustomername !=null&&"".equals(customerVo.getCustomername ) ){
query.setParamter("customername",customername);
}
if(customerVo.getOrderByStr !=null&&"".equals(customerVo.getOrderByStr ) ){
query.setParamter("orderByStr",orderByStr);
}
}
}
StringBuffer hql=new StringBuffer("rom IDCCustomer ic where 1=1 ");
List list=new ArrayList();
if(customerVo|=null){
if(customerVo.getCustomerid!=null&&"".equals(customerVo.getCustomerid) ){
hql.append(" and ic.customerid=:customerid");
}
if(customerVo.getCustomername !=null&&"".equals(customerVo.getCustomername ) ){
hql.append(" and ic.customername =:customername ");
}
//customerVo.orderByStr 保存内容格式 :"customername desc/customername asc ......"
if(customerVo.getOrderByStr !=null&&"".equals(customerVo.getOrderByStr ) ){
hql.append(" order by :orderByStr customerid desc");
}
}
Query query = this.getSession().createQuery(hql);
query.setFirstResult(pageHolder.getFirstIndex());
query.setMaxResults(pageHolder.getPageSize());
if(customerVo|=null){
if(customerVo.getCustomerid!=null&&"".equals(customerVo.getCustomerid) ){
query.setParamter("customerid",customerid);
}
if(customerVo.getCustomername !=null&&"".equals(customerVo.getCustomername ) ){
query.setParamter("customername",customername);
}
if(customerVo.getOrderByStr !=null&&"".equals(customerVo.getOrderByStr ) ){
query.setParamter("orderByStr",orderByStr);
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询