页面显示:没有输出该显示的数据
请问是不是hql语句写错了?还是哪里不对?求解^^
DAOImpl中的部分代码:
private int getTotalRecords2(String houseAddress, int priceTop,int priceBottom)
{
Session session=this.getSessionFactory().getCurrentSession();
String hql = "select count(*) from House h where h.houseAddress like ? and h.housePrice>=? and h.housePrice<=? and h.houseState=1 "; //HQL 查询语句
Query query = session.createQuery(hql); //创建Query 对象
query.setParameter(0, "%"+houseAddress+"%");
query.setParameter(1, priceBottom);
query.setParameter(2, priceTop);
Long totalRecords = (Long) query.uniqueResult(); //单值检索
return totalRecords.intValue(); //返回总记录数
} //分页查询信息方法findPaging2()
@Override
public PageModel findPaging2(String houseAddress, int priceTop,int priceBottom, int currPage, int pageSize) {
Session session = null; //Session对象
PageModel pageModel = null;
session = this.getSessionFactory().getCurrentSession(); //获取Session
session.beginTransaction(); //开启事务
String hql = "from House h where h.houseAddress like ? and h.housePrice>=? and h.housePrice<=? and h.houseState=1"; //HQL 查询语句,按留言时间降序排序
Query query=session.createQuery(hql);
query.setParameter(0, "%"+houseAddress+"%");
query.setParameter(1, priceBottom);
query.setParameter(2, priceTop) //创建Query 对象
.setFirstResult((currPage - 1) * pageSize) //设置起始位置
.setMaxResults(pageSize);
@SuppressWarnings("unchecked")
List<House> list = query.list(); //返回结果集
System.out.println("size="+list.size());
pageModel = new PageModel(); //实例化pageModel
pageModel.setCurrPage(currPage); //设置当前页
pageModel.setList(list); //设置结果集
pageModel.setPageSize(pageSize); //设置每页记录数
pageModel.setTotalRecords(getTotalRecords2( houseAddress,priceTop,priceBottom));//设置总记录数
session.getTransaction().commit(); //提交事务
return pageModel;
}sessionhqlj2eehibernate对象
请问是不是hql语句写错了?还是哪里不对?求解^^
DAOImpl中的部分代码:
private int getTotalRecords2(String houseAddress, int priceTop,int priceBottom)
{
Session session=this.getSessionFactory().getCurrentSession();
String hql = "select count(*) from House h where h.houseAddress like ? and h.housePrice>=? and h.housePrice<=? and h.houseState=1 "; //HQL 查询语句
Query query = session.createQuery(hql); //创建Query 对象
query.setParameter(0, "%"+houseAddress+"%");
query.setParameter(1, priceBottom);
query.setParameter(2, priceTop);
Long totalRecords = (Long) query.uniqueResult(); //单值检索
return totalRecords.intValue(); //返回总记录数
} //分页查询信息方法findPaging2()
@Override
public PageModel findPaging2(String houseAddress, int priceTop,int priceBottom, int currPage, int pageSize) {
Session session = null; //Session对象
PageModel pageModel = null;
session = this.getSessionFactory().getCurrentSession(); //获取Session
session.beginTransaction(); //开启事务
String hql = "from House h where h.houseAddress like ? and h.housePrice>=? and h.housePrice<=? and h.houseState=1"; //HQL 查询语句,按留言时间降序排序
Query query=session.createQuery(hql);
query.setParameter(0, "%"+houseAddress+"%");
query.setParameter(1, priceBottom);
query.setParameter(2, priceTop) //创建Query 对象
.setFirstResult((currPage - 1) * pageSize) //设置起始位置
.setMaxResults(pageSize);
@SuppressWarnings("unchecked")
List<House> list = query.list(); //返回结果集
System.out.println("size="+list.size());
pageModel = new PageModel(); //实例化pageModel
pageModel.setCurrPage(currPage); //设置当前页
pageModel.setList(list); //设置结果集
pageModel.setPageSize(pageSize); //设置每页记录数
pageModel.setTotalRecords(getTotalRecords2( houseAddress,priceTop,priceBottom));//设置总记录数
session.getTransaction().commit(); //提交事务
return pageModel;
}sessionhqlj2eehibernate对象
解决方案 »
- 说是内存溢出,我看怎么不像
- ssh2 配置问题
- 服务器怎样判断客户端的设备是电脑还是PDA
- 请问大家用ejb3.0开发的时候, 用什么工具生成实体bean和dao啊
- Spring+jersey配置,访问时出javax.ws.rs.core.UriBuilder.uri方法异常
- 怎么取到iframe中的某个参数的值???谢谢!!
- 高手来,struts 多文件上传问题,高手!进!~进!~进!~
- 有谁知道servlet 是否能和 flash 通讯 !!!!!!!!!!!!!!!!!
- 如何在TOMCAT里安装已经编译好的SERVLET?
- 关于数据库关闭操作
- 顺序链表的操作
- struts2的action 使用了多线程,如何获取getRequest信息
query.setParameter(0, houseAddress);
这样吧
把
query.setParameter(0, "%"+houseAddress+"%");
改为
query.setParameter(0, "'%"+houseAddress+"%'");查不出来这样的问题可以先把sql打出来自己查数据库,那样比较容易看出问题
结果还是没有查到。我用SQL编辑器中能够查到数据,但是这边老出错。以下是操作截图:
查询前:查询后:
like %?%
query.setParameter(0, houseAddress);