gethibernatetemplate.find方法详解

gethibernatetemplate.find方法详解

ID:34723098

大小:50.76 KB

页数:10页

时间:2019-03-10

gethibernatetemplate.find方法详解_第1页
gethibernatetemplate.find方法详解_第2页
gethibernatetemplate.find方法详解_第3页
gethibernatetemplate.find方法详解_第4页
gethibernatetemplate.find方法详解_第5页
资源描述:

《gethibernatetemplate.find方法详解》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、getHibernateTemplate().find方法详解Spring中常用的hql查询方法(getHibernateTemplate())---------------------------------一、find(StringqueryString);    示例:this.getHibernateTemplate().find("frombean.User");    返回所有User对象二、find(StringqueryString,Objectvalue);    示例:this.getHibernateTemplate().f

2、ind("frombean.Useruwhereu.name=?","test");    或模糊查询:this.getHibernateTemplate().find("frombean.Useruwhereu.namelike?","%test%");    返回name属性值为test的对象(模糊查询,返回name属性值包含test的对象)三、find(StringqueryString,Object[]values);    示例:Stringhql="frombean.Useruwhereu.name=?andu.password=?"

3、              this.getHibernateTemplate().find(hql,newString[]{"test","123"});    返回用户名为test并且密码为123的所有User对象---------------------------------四、findByExample(ObjectexampleEntity)    示例:           Useru=newUser();              u.setPassword("123");//必须符合的条件但是这两个条件时并列的(象当于sql中的

4、and)              u.setName("bb");              list=this.getHibernateTemplate().findByExample(u,start,max);     返回:用户名为bb密码为123的对象五、findByExample(ObjectexampleEntity,intfirstResult,intmaxResults)    示例:          Useru=newUser();             u.setPassword("123");//必须符合的条件但是这两

5、个条件时并列的(象当于sql中的and)             u.setName("bb");             list=this.getHibernateTemplate().findByExample(u,start,max);       返回:满足用户名为bb密码为123,自start起共max个User对象。(对象从0开始计数)---------------------------------------------------六、findByNamedParam(StringqueryString,StringparamN

6、ame,Objectvalue)  使用以下语句查询:       StringqueryString="selectcount(*)frombean.Useruwhereu.name=:myName";       StringparamName="myName";       Stringvalue="http://www.cnblogs.com/gywbg/archive/2012/04/28/xiyue";       this.getHibernateTemplate().findByNamedParam(queryString,par

7、amName,value);       System.out.println(list.get(0));   返回name为xiyue的User对象的条数七、findByNamedParam(StringqueryString,String[]paramName,Object[]value)    示例:       StringqueryString="selectcount(*)frombean.Useruwhereu.name=:myNameandu.password=:myPassword";       String[]paramNa

8、me=newString[]{"myName","myPassword"};       String[]value=http://ww

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。