- 2
- 0
- 约6.33千字
- 约 9页
- 2015-09-26 发布于重庆
- 举报
Spring中常用的hql查询方法
Spring中常用的hql查询方法(getHibernateTemplate())一、find(String queryString);
????? 示例:this.getHibernateTemplate().find(from bean.User);
????? 返回所有User对象二、find(String queryString , Object value);
????? 示例:this.getHibernateTemplate().find(from bean.User u where u.name=?, test);
????? 或模糊查询:this.getHibernateTemplate().find(from bean.User u where u.name like ?, %test%);
????? 返回name属性值为test的对象(模糊查询,返回name属性值包含test的对象)三、find(String queryString, Object[] values);
????? 示例:String hql= from bean.User u where u.name=? and u.password=?
??????????????? this.getHibernateTemplate().find(hql, new String[]{test, 123});
????? 返回用户名为test并且密码为123的所有User对象四、findByExample(Object exampleEntity)
????? 示例:
???????????? User u=new?User();????
???????????? u.setPassword(123);//必须?符合的条件但是这两个条件时并列的(象当于sql中的and)????
?? ? ? ? ? ? u.setName(bb);????
??? ? ? ? ?? list=this.getHibernateTemplate().findByExample(u,start,max);??
????? 返回:用户名为bb密码为123的对象五、findByExample(Object exampleEntity, int firstResult, int?maxResults)
????? 示例:
??? ? ? ? ? User?u=new?User();????
??????????? u.setPassword(123);//必须?符合的条件但是这两个条件时并列的(象当于sql中的and)????
??????????? u.setName(bb);????
??????????? list=this.getHibernateTemplate().findByExample(u,start,max);????
????? 返回:满足用户名为bb密码为123,自start起共max个User对象。(对象从0开始计数)六、findByNamedParam(String queryString , String paramName , Object value)??? 使用以下语句查询:?
??? ? ?? String queryString =?select?count(*)?from bean.User u where u.name=:myName;?
???????? String paramName= myName;
???????? String value= xiyue;
???????? this.getHibernateTemplate().findByNamedParam(queryString, paramName, value);?
???????? System.out.println(list.get(0));?
???? 返回name为xiyue的User对象的条数七、findByNamedParam(String queryString , String[] paramName , Object[] value)
????? 示例:
???????? String queryString =?select?count(*)?from bean.User u where u.name=:myName and u.password=:myPassword;?
???????? String[] paramName= new String[]{myName, myPassword};
???????? String[] value= new String[]{xiyue, 123};
???????? this.g
您可能关注的文档
- Proceedings of the Conference on Wavelet Analysis and Applications Applications.pdf
- ProENGINEER与AutoCAD文档转换技巧研究.pdf
- proe教程图形(Graph)在可变中的循环利用和应用.doc
- ProE中经典问题及evalgraph函数的应用.doc
- PROFIBUSDP水质监测中冗余网络的FPGA逻辑设计.pdf
- PROFIBUSDP现场总线在机械压力机上的应用.pdf
- Progress toward the Determination of Complete Vertex Operators for The IIB Matrix Model.pdf
- project option的应用.pdf
- Progressive and Discrete Auctions a Finite Sample Evaluation Based on Dominated Strategies.pdf
- Projective Dynamics Analysis of Magnetization Reversal.pdf
- 2026年闽南理工学院单招职业适应性考试题库精编答案详解.docx
- 2026年阳江职业技术学院单招职业技能考试题库及答案详解(网校专用).docx
- 2026年长沙环境保护职业技术学院单招职业倾向性考试题库及答案详解(最新).docx
- 2026年黑龙江省大庆市单招职业倾向性考试题库及答案详解(网校专用).docx
- 2026年长春金融高等专科学校单招职业技能考试题库及1套完整答案详解.docx
- 2026年青岛工程职业学院单招职业技能考试题库及答案详解参考.docx
- 2026年陕西青年职业学院单招职业适应性考试题库及答案详解(历年真题).docx
- 2026年闽西职业技术学院单招职业技能考试题库带答案详解.docx
- 2026年阜新高等专科学校单招职业技能考试题库精选答案详解.docx
- 2026年鹤岗师范高等专科学校单招职业适应性考试题库附答案详解(名师推荐).docx
最近下载
- 人美版美术一年级下册《第一单元 春天的故事》大单元教学设计2026.docx VIP
- 公转私借款合同范本.docx VIP
- IATF16949:2016中文版本含ISO9001全文依据2025年11月SI更新(包括SI1-30).pdf
- 4.成人斯蒂尔病诊疗指南2025版.pptx
- 第一单元《春天的故事》大单元(教学设计)人美版2025美术一年级下册.docx VIP
- ISO42001-2023人工智能管理体系程序文件.docx VIP
- 一种火炬排放系统密封器.pdf VIP
- 提高住院患者大小便标本送检率PDCA.pptx VIP
- DB61_T 2093.5-2025 猕猴桃生产第5部分:花粉生产.docx VIP
- 无锡市轨道交通工程临时用电监理实施细则.doc VIP
原创力文档

文档评论(0)