hibernate 多条件组合查询之sql拼接
hibernate 多条件组合查询之sql拼接
- 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拼接相关推荐
- SQL如何构建多条件组合查询,而且不降低效率
我们知道,在一般的信息系统中,特别是主要信息表,如客户基本信息,工单受理主界面,用户会用到多条件组合查询. 我看过一些系统,有的人是采用将一个表的栏位给用户选择,然后用户可以针对某一栏位来下条件,但是 ...
- 树控件,多条件组合查询与混合数据源
//实现多条件查询 //...连接数据库的代码 SqlDataAdapter sda = new SqlDataAdapter(sql,con); DataTable dt = new DataTab ...
- solr的多条件组合查询和solr的范围查询【转】
solr的多条件组合查询和solr的范围查询 版权声明:本文为博主原创文章,供大家参考,但不要抄袭哦! 存在问题:为了减轻数据库的访问压力,往往我们将必要的数据存储到solr中,并给部分字段建立索引, ...
- 多条件组合查询+分页
比较麻烦,把他记录下来. 前台UI: 实现的类代码: 程序代码 /// <summary> /// 多条件组合查询 /// </summary> ...
- 亿级数据多条件组合查询——秒级响应解决方案
1 概述 组合查询为多条件组合查询,在很多场景下都有使用.购物网站中通过勾选类别.价格.销售量范围等属性来对所有的商品进行筛选,筛选出满足客户需要的商品,这是一种典型的组合查询.在小数据量的情况下,后 ...
- php js脚本查询php,php结合js实现多条件组合查询
本文实例为大家分享了php结合js实现多条件组合查询的具体代码,供大家参考,具体内容如下 一.效果图 二.前端代码 Jquery分类 .templinkactive { padding:5px; te ...
- 条件查询_多条件组合查询---测试用例设计
一.假设查询因子:A,B,C,D,E(下拉框+复选框) 1.单独查询:A:B:C:D:E - 确保单独查询的正确性,这也是最基本的. 2.两个组合查询:AB:AC:AD:AE:BC:BD:BE:CD: ...
- 《MySQL数据操作与查询》- 维护学生信息、老师信息和成绩信息 支持按多种条件组合查询学生信息和成绩信息
综合项目需求 一.系统整体功能 系统需支持以下功能: 维护学生信息.老师信息和成绩信息 支持按多种条件组合查询学生信息和成绩信息 学生 Student(id,班级id,学号,姓名,性别,电话,地址,出 ...
- solr的多条件组合查询
今天,再工作中遇到了solr的多条件组合查询,于是在网上查到一些博客--多条件查询,这篇写的不错,但是我也想把我自己的记录下来.话不多说,直接放代码.注意:,在接收的参数由于都是String类型的,所 ...
最新文章
- 区分C语言中getch、getche、fgetc、getc、getchar、fgets、gets
- (简要介绍)Winograd schema challenge(Winograd question)
- [工具]-C语言实现:生成一个全是0x0的二进制文件
- php操作redis phpredis扩展
- 前端学习(1837):前端面试题之变量提升
- 【亲测有效】运行docker ps 出现Got permission denied问题的解决方案
- tensorflow之eval
- java simpedateformat_java中Date,SimpleDateFormat
- 2022上半年软件设计师历年真题
- canvas 加载图片
- python课设答辩ppt_学生成绩管理系统答辩幻灯片.ppt
- 嵌入式通过序列号加密总结及flash…
- POJ - 3311- Hie with the Pie ( 状压dp )
- 如何在ipone自带邮件上添加网易邮箱
- 性能测试:深入理解并发量,线程数,吞吐量,TPS
- Coding and Paper Letter(七十六)
- Linux下c语言文本方式文件读取
- 基于Python的Django框架的二手物品交易平台的设计与实现
- 中国羟丙甲纤维素胶囊市场深度研究分析报告
- aardio - nanomsg/nnmsg/nnm 消息发送模式图示
热门文章
- 字符串经典题之扑克牌的大小
- 动态随机存储器的刷新(集中刷新、分散刷新、异步刷新的区别)
- KVM复制虚拟机,KVM克隆虚拟机
- phpstudy下载、安装、配置、网站部署、卸载(windows下php、apache、nginx环境测试)
- C/C++ 去掉字符串首位的空格字符
- Python 使用ntplib库同步校准当地时间的方法 (NTP)
- Linux C线程同步的三种方法
- LeetCode 20. Valid Parentheses(c++)
- [转] Oracle学习之创建数据库(新建实例)
- 《媒体曝70多万种药品“底价”:普遍超厂价5-6倍》——典型的媒体噱头唬人行为...