日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hibernate 多条件组合查询之sql拼接

發布時間:2025/3/16 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hibernate 多条件组合查询之sql拼接 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
hibernate 多條件組合查詢之sql拼接?

?

[java]?view plaincopyprint?
  • public?static?void?main(String[]?args)?{??
  • Session?session?=?null;???
  • Transaction?tx?=?null;???
  • List?list?=?null;???
  • Criteria?criteria?=?null;???
  • try?{???
  • session?=?HibernateSessionFactory.getSession();???
  • tx?=?session.beginTransaction();???
  • DetachedCriteria?detachedCriteria?=?DetachedCriteria???
  • .forClass(InfoTab.class);???
  • String?sql="?1=1?";???
  • Integer?pareaId?=?0;?//?父地區;???
  • Integer?careaId?=?0;?//?子地區;???
  • Integer?categoryId?=?0;?//?類別;???
  • String?infoPrivider?=?"中介";?//?來源;???
  • String?houseType=?"地下室";?//?房屋類型;???
  • Integer?hxBedRoom=0;?//?室;???
  • Integer?hxLivingRoom=0;?//?廳;???
  • String?hzHouseStatus="有房出租";?//?合租類型;???
  • String?hzRequestSex="男";?//?性別要求;???
  • String?fixUp="尚未";?//?裝修程度;???
  • Integer?lcHeightMolecuse=0;?//?樓層;???
  • String?orientation="東南";?//?朝向要求;???
  • Integer?buildArea=2000;?//?建筑面積;???
  • Integer?useArea=80;?//?使用面積;???
  • Integer?rentalDigit=2000;?//?租金/價格;???
  • String?title=?"出租";?//?標題;???
  • if(pareaId!=0)???
  • {???
  • sql+="pareaId="?+?pareaId;???
  • }???
  • if(careaId!=0)???
  • {???
  • sql+="?and?careaId="?+?careaId;???
  • }???
  • if(categoryId!=0)???
  • {???
  • sql+="?and?categoryId="?+?categoryId;???
  • }???
  • if(!infoPrivider.equals(""))???
  • {???
  • sql+="?and?infoPrivider='"?+?infoPrivider?+?"'";???
  • }???
  • if(!houseType.equals(""))???
  • {???
  • sql+="?and?houseType='"?+?houseType?+"'";???
  • }???
  • if(hxBedRoom!=0)???
  • {???
  • sql+="?and?hxBedRoom="?+?hxBedRoom;???
  • }???
  • if(hxLivingRoom!=0)???
  • {???
  • sql+="?and?hxLivingRoom="?+?hxLivingRoom;???
  • }???
  • if(!hzHouseStatus.equals(""))???
  • {???
  • sql+="?and?hzHouseStatus='"?+?hzHouseStatus?+?"'";???
  • }???
  • if(!hzRequestSex.equals(""))???
  • {???
  • sql+="?and?hzRequestSex='"?+?hzRequestSex?+"'";???
  • }???
  • if(!fixUp.equals(""))???
  • {???
  • sql+="?and?fixUp='"?+?fixUp?+?"'";???
  • }???
  • if(lcHeightMolecuse!=0)???
  • {???
  • sql+="?and?lcHeightMolecuse="?+?lcHeightMolecuse;???
  • }???
  • if(!orientation.equals(""))???
  • {???
  • sql+="?and?orientation='"?+?orientation?+?"'";???
  • }???
  • if(buildArea!=0)???
  • {???
  • sql+="?and?buildArea="?+?buildArea;???
  • }???
  • if(useArea!=0)???
  • {???
  • sql+="?and?useArea="?+?useArea;???
  • }???
  • if(rentalDigit!=0)???
  • {???
  • sql+="?and?rentalDigit="?+?rentalDigit;???
  • }???
  • if(!title.equals(""))???
  • {???
  • sql+="?and?title?like?'%"?+?title?+?"%'";???
  • }???
  • sql+="?order?by?id?desc";???
  • System.out.println(sql);???
  • detachedCriteria.add(Restrictions.sqlRestriction(sql));???
  • criteria?=?detachedCriteria.getExecutableCriteria(session);???
  • list?=?criteria.list();???
  • for(int?i=0;i<list.size();i++)???
  • {???
  • InfoTab?infoTab?=?(InfoTab)list.get(i);???
  • System.out.println(infoTab.getTitle()?+"?"+?infoTab.getCategoryId()?+"?"+?infoTab.getPareaName()?+"?"+?infoTab.getCareaName()?+"?"?+?infoTab.getHouseType()?+"?"?+?infoTab.getInfoPrivider());???
  • }???
  • tx.commit();???
  • }?catch?(HibernateException?he)?{???
  • he.printStackTrace();???
  • }???
  • } ?
  • 總結

    以上是生活随笔為你收集整理的hibernate 多条件组合查询之sql拼接的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。