关于hibernate 分页问题

q943642385 2011-07-15 11:37:03
师兄们 情况是这样的:
表里一共有11条数据。但是每次读取全是前十条,我不知道剩下的一条在哪里,JSP页面上也是现实就一页

...全文
102 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
q943642385 2011-07-15
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 zn85600301 的回复:]

贴出你的分页代码 DAO层的
[/Quote]

貌似 hibernate 自带的
zn85600301 2011-07-15
  • 打赏
  • 举报
回复
贴出你的分页代码 DAO层的
q943642385 2011-07-15
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 pipi517 的回复:]

query.setFirstResult 是从0开始表示第一条的>

你看一下你的page.getBeginIndex()
[/Quote]

page.getBeginIndex() 输出的值是0
皮皮 2011-07-15
  • 打赏
  • 举报
回复
query.setFirstResult 是从0开始表示第一条的>

你看一下你的page.getBeginIndex()
q943642385 2011-07-15
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zl3450341 的回复:]

1。确保你分页的时候,点“上一页”,“下一页”,传过去的当前页,这个参数的值正确。
2。确定hibernate代码正确。

多调试一下吧
[/Quote]


我新手代码乱 将就看吧 好吗
q943642385 2011-07-15
  • 打赏
  • 举报
回复
DAO

/**查处系统信息*/
public List<CfMessage> getmessage(String corId,Page page){
StringBuffer hql=new StringBuffer();
hql
.append("SELECT cf_message.Msg_ID,cf_message.Msg_To,cf_message.Msg_From,cf_message.Msg_Title,cf_message.Msg_Pro_Id,cf_message.Msg_Parent_Id,cf_message.Msg_IsRead,cf_message.Msg_IsDel FROM cf_message WHERE cf_message.Msg_IsDel=0 AND cf_message.Msg_From='system' and cf_message.Msg_To='"+corId+"' order by cf_message.Msg_Time desc");
Query query=this.getSession().createSQLQuery(hql.toString());
query.setFirstResult(page.getBeginIndex()).setMaxResults(page.getEveryPage());
List<CfMessage> list=query.list();
System.out.println(page.getBeginIndex()+"......."+page.getEveryPage());
if(getSession()!=null){
getSession().flush();
getSession().close();
}

System.out.println("*******"+hql.toString());
return list;
}

/**查出系统信息的对大条数*/
public int getmessageCount(String name){
StringBuffer sql = new StringBuffer();
sql.append("SELECT COUNT(mess.Msg_ID) FROM cf_message mess where mess.Msg_From='system' and mess.Msg_To='"+name+"'");
Query query=getSession().createSQLQuery(sql.toString());
List list =query.list();
System.out.println("}}}}}}}}}}}"+list.size()+".............");
if(getSession()!=null){
getSession().flush();
getSession().close();
}
System.out.println("-----"+sql.toString());
return Integer.valueOf(list.get(0).toString());
}

}
q943642385 2011-07-15
  • 打赏
  • 举报
回复
action


public String getMoreMessage(){
cfCorporation = (CfCorporation) this.session.get("cfCorporation");
if (cfCorporation == null) {
passworderr = "超时,请重新登录!";
return "login";
}
int productSize = messageService.getmessageCount(cfCorporation.getCorId());
page = new Page();
page.setEveryPage(ConstantUtil.EVERYPAGE_SIZE);
//page.setBeginIndex(page.getEveryPage());
page.setCurrentPage(goPage);
System.out.println("0000+"+page.getHasPrePage());
messageList = messageService.getMoreSystemMess(cfCorporation.getCorId(),page);
page = PageUtil.createPage(page, messageList.size());
goPage = page.getCurrentPage();
name=cfCorporation.getCorId();
List<CfMessage> list = new ArrayList<CfMessage>();
qrdd = messageList.size();
for (CfMessage message : messageList) {
if (message.getMsgIsRead() == 0) {
list.add(message);
}
}
qrfh = list.size();
return SUCCESS;
}
哎呦喂哈 2011-07-15
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zl3450341 的回复:]
1。确保你分页的时候,点“上一页”,“下一页”,传过去的当前页,这个参数的值正确。
2。确定hibernate代码正确。

多调试一下吧
[/Quote]
++
zl3450341 2011-07-15
  • 打赏
  • 举报
回复
1。确保你分页的时候,点“上一页”,“下一页”,传过去的当前页,这个参数的值正确。
2。确定hibernate代码正确。

多调试一下吧
zl3450341 2011-07-15
  • 打赏
  • 举报
回复
你代码如何写的?

贴代码出来

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧