- 1、本文档共38页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
-*- 投影 String hql = select c.id, c.userName from Customer c ; Query query = session.createQuery(hql); ListObject[ ] list = query.list(); for(Object[ ] objs :list) { System.out.println(objs[0]+ +objs[1]); } String hql = select new Customer(c.id, c.userName) from Customer c ; Query query = session.createQuery(hql); ListCustomer list = query.list(); for(Customer c :list) { System.out.println(c.getId() + + c.getUserName()); } 必须有对应的构造方法 String hql = select new CustomerRow(c.id, c.userName) from Customer c ; String hql = select new map(c.id, c.userName) from Customer c ; 不能得到完整的对象,只能得到Object[ ] -*- 分组与统计 - HQL HQL select count(c.id) from Customer c select avg(c.age) from Customer c select max(c.age) ,min(c.age) from Customer c select c.userName,count(o) from Customer c left join c.orders o group by c.id select c.userName,count(o) from Customer c left join c.orders o group by c.id having count(o)=1 -*- 分组与统计 - Criteria 使用Projection接口实现以Criteria方式进行分组与统计查询 方法名 描述 avg(String propertyName) 对某个属性求平均值 max(String propertyName) 对某个属性求最大值 min(String propertyName) 对某个属性就最小值 sum(String propertyName) 对某个属性求和 count(String propertyName) 根据某个属性来统计记录数,和count(propertyName)类似 rowCount() 统计行数,与count(*)类似 countDistinct(String propertyName) 不重复的统计记录数,与count(distinct propertyName)类似 groupProperty(String propame) 根据特定属性分组,与group by proname类似 projectionList() 返回一个ProjectionList对象数组,代表投影列表 property(String propertyName) 把某个属性加入到投影查询中 -*- HQL动态查询 StringBuffer buffer = new StringBuffer(); //生成基础SQL buffer.append(from Customer c where 1=1); //如果name满足条件,则加入语句中 if (name != null) buffer.append( and c.userName like :name); //如果age满足条件,则加入语句中 if (age != null age != 0) buffer.append( and c.age = :age); Query query = session.createQuery(buffer.toString()); if (name != null) query.setString(name, % + name.toLowerCase() + %); if (age != null age != 0) query.setInteger(age, age); return query.list(); -*- Criteria动态查询 Criteria criteria = session.createCriteria(C
您可能关注的文档
- (电子产品案例实践)第5章印刷电路板(PCB)设计.ppt
- (电子产品案例实践)第6章印刷电路板制作.ppt
- (电子产品案例实践)第7章焊接与调试.ppt
- (模拟电子技术及应用)第八章常用电子仪器.ppt
- (模拟电子技术及应用)第二章放大电路及其分析.ppt
- (模拟电子技术及应用)第九章模拟电子技术实验.ppt
- (模拟电子技术及应用)第六章直流稳压电源.ppt
- (模拟电子技术及应用)第七章低频功率放大电路.ppt
- (模拟电子技术及应用)第三章负反馈放大电路.ppt
- (模拟电子技术及应用)第五章波形产生与变换电路.ppt
- 2024年02月[江苏]2024招商银行苏州分行春季校园招考笔试历年参考题库附带答案详解.docx
- 2024年02月[新疆]2024年乌鲁木齐银行高层次人才招考(216)笔试历年参考题库附带答案详解.docx
- 2024年02月[江苏]2024年宁波银行无锡分行校园招考空中宣讲会笔试历年参考题库附带答案详解.docx
- 2024年02月[江苏]中国民生银行徐州分行招考笔试历年参考题库附带答案详解.docx
- 2024年02月[江苏]兆丰国际商业银行苏州分行招考笔试历年参考题库附带答案详解.docx
- 2024年02月[江苏]华夏银行宿迁分行(筹)招考笔试历年参考题库附带答案详解.docx
- 2025年中国折叠烟箱机器人行业投资前景及策略咨询研究报告.docx
- 2025年中国折叠式天篷帘行业投资前景及策略咨询研究报告.docx
- 2025年中国折叠式新弓型展架市场调查研究报告.docx
- 2025年中国捆绑式多管除尘器市场调查研究报告.docx
最近下载
- 绿城好房子体系.pptx
- AI在计算机科学教学中的应用论文.docx
- 人教版七年级历史下册期末试卷(含答案).pdf VIP
- 员工手册电子版员工手册电子版.doc VIP
- 【高考数学押题卷】2025年全国100所名校高考模拟示范卷七含答案或解析.pdf
- 孚瑞肯FR100系列变频器使用说明书.pdf
- 开放系统22226《物业管理实务(2)》期末机考真题及答案(第101套).docx
- 武侯区2018-2019学年五年级下数学调考试卷-.pdf VIP
- 尪痹(类风湿关节炎)中医护理效果评价表.docx VIP
- J B-T 10441.3-2004 电工用皱纹绝缘纸 第3部分 技术要求.pdf VIP
文档评论(0)