分页查询

来源:互联网 发布:mac用ie浏览器 编辑:程序博客网 时间:2024/05/16 06:24


//这里添加查询count的接口
 public int Count(ImagesInfoCondition con,int start,int pageSize){
  int count = 0;
  //这里添加sql语句
  String sql=" select COUNT(1) from( "+
       " SELECT count(1) from picturemanage_images_info p " + " where 1=1 and p.type='文物' ";
  //名称名词关联搜索
  if(con.getWenName()!=null && !con.getWenName().toString().equals("")){
   sql+=" and ( ";
   List<String> wenNameList = parameterRelationManager.getValueByName(con.getWenName());
   for(String name:wenNameList){
    sql+=" p.wen_name like '%"+name+"%' or ";
   }
    sql=sql.substring(0, sql.length()-3);
    sql+=" ) ";
   } if(con.getLikePicCode()!=null && !con.getLikePicCode().trim().equals("")){
     sql+=" and p.pic_code like '%"+con.getLikePicCode()+"%'";
   } if(con.getWenLevel()!=null && !con.getWenLevel().equals("")){
     sql+=" and p.wen_level = "+"'"+con.getWenLevel()+"'";
   }
   //质地关联搜索
   if(con.getWenTextureIds().size()!=0 ){
    sql+=" and ( ";
    for(String name:con.getWenTextureIds()){
      sql+=" p.wen_texture = "+"'"+name+"'"+" or ";
    }
    sql=sql.substring(0, sql.length()-3);
    sql+=" ) ";
   }
   //年代关联搜索
   if(con.getWenAgeIds().size()!=0 ){
    sql+=" and ( ";
    for(String name:con.getWenAgeIds()){
     sql+=" p.wen_age = "+"'"+name+"'"+" or ";
    }
    sql=sql.substring(0, sql.length()-3);
    sql+=" ) ";
   } if(con.getPhotoAngle()!=null && !con.getPhotoAngle().equals("")){
    sql+=" and p.photo_angle = "+"'"+con.getPhotoAngle()+"'";
   } if(con.getPhotoLocale()!=null && !con.getPhotoLocale().equals("")){
    sql+=" and p.photo_local = "+"'"+con.getPhotoLocale()+"'";
   } if(con.getPhotoGrapher()!=null && !con.getPhotoGrapher().equals("")){
    sql+=" and p.photo_grapher = "+"'"+con.getPhotoGrapher()+"'";
   } if(con.getCameraTimeStart()!=null && !con.getCameraTimeStart().equals("")){
    sql+=" and p.camera_time > "+DateUtil.formatDate(con.getCameraTimeStart(), "yyyy-MM-dd");
   } if(con.getCameraTimeEnd()!=null && !con.getCameraTimeEnd().equals("")){
    sql+=" and p.camera_time < '"+DateUtil.formatDate(con.getCameraTimeEnd(), "yyyy-MM-dd 23:59:59")+"'";
   } if(con.getCollectType()!=null && !con.getCollectType().equals("")){
    sql+=" and p.collect_type = "+"'"+con.getCollectType()+"'";
   }
   //描述关联搜索
   if(con.getDescriptionList().size()>0){
    sql+=" and ( ";
    for(String name:con.getDescriptionList()){
     sql+=" p.description like '%"+name+"%' or ";
    }
    sql=sql.substring(0, sql.length()-3);
    sql+=" ) ";
   }
  //根据pic_code分组查询---结尾
  sql+=" GROUP BY pic_code) count " ;
  Query query = sessionFactory.getCurrentSession().createSQLQuery(sql);
  List list = query.list();
  count = Integer.parseInt(list.get(0).toString());
  return count;
 }


 Integer curPage = 0;   //cp:当前页
  Integer totalCount = 0;   //总记录数
  Integer pageSize = 24;   //ps:每页数量

//执行查询(分页)
  int start = curPage * pageSize;//当前页*每页数量
  if(start<0) start = 0;

totalCount = imagesInfoManager.Count(cond, start, pageSize);

0 0