StringBuffer sb = new StringBuffer(); String sql ="select count(*) from Major m where 1=1 "; if(majorname != null && !"".equals(majorname)){ sb.append(" and m.majorname like "); sb.append("%"+ majorname +"%"); } if(traininglevel != null && !"".equals(traininglevel)){ sb.append(" and m.traininglevel= "); sb.append(traininglevel); } if(version !=null && !"".equals(version)) { sb.append(" and m.version= "); sb.append(version); } String hql1 = sql + sb.toString(); int tatolSize = majorService.getTatolSize(hql1); StringBuffer hql = new StringBuffer(); hql.append(" from Major m INNer Join Traininglevel t "); hql.append(" ON m.traininglevel=t.id where 1=1 "); hql.append(sb); hql.append(" ORDER BY m.id ASC "); hql.append(" limit "); int index = (currentPage - 1) * pageSize ; hql.append(index+","); hql.append(pageSize); List<Major> list = majorService.findByCondition(hql.toString()); PageBean<Major> pb = new PageBean<Major>(); pb.setCurrentPage(currentPage); pb.setTatolSize(tatolSize); pb.setPageData(list); // 封装当前页; 如果没有搜索到值,即总记录数为0,当前页也是0 if (tatolSize == 0){ pb.setCurrentPage(0); }else{ pb.setCurrentPage(currentPage); } return pb;
添加回答
举报
0/150
提交
取消