hibernate 多条件组合查询之sql拼接
来源:互联网 发布:系统还原数据会消失吗 编辑:程序博客网 时间:2024/04/26 18:39
- 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 拼接
- hibernate 多条件组合查询之sql拼接
- hibernate 多条件组合查询之sql拼接
- hibernate 多条件组合查询之sql拼接
- 多条件查询(Sql拼接)
- Hibernate多条件查询,HQL拼接
- C# SQL多条件查询拼接技巧
- SQL多条件查询拼接in中条件方法
- 多条件组合查询SQL优化一则
- linq to sql 多条件组合查询
- 多条件组合查询,sql语句连接
- 多条件查询的sql语句字符串拼接
- 三层模式中,多条件查询中的sql语句拼接
- ef 动态条件 查询 组合查询 配置 expession 拼接参考
- LINQ To SQL 拼接查询条件
- php根据查询条件拼接sql语句
- 根据条件查询动态拼接sql语句
- 动态sql语句拼接查询条件
- matlab学习--mat文件
- 【Sencha Toucha】Sencha Touch ExtJs 给 Button 添加图片
- (转)sharedUserId和签名Android权限
- 简单线性表
- 函数
- hibernate 多条件组合查询之sql拼接
- ubuntu 深度音乐播放器
- android intent
- 图片转换成二进制与二进制转换成图片
- Dungeon Master (P2251)
- (转)Android很有用的代码片段
- perl正则表达式
- ActiveMQ 中的持久订阅配置
- VC++ 获取系统特殊文件夹的路径 桌面等