Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > Java > spring、ibatis控制oracle分页的问题
【标  题】:spring、ibatis控制oracle分页的问题
【关键字】:spring,ibatis,oracle
【来  源】:http://www.blogjava.net/ctguzhupan/archive/2006/08/30/66580.html

spring、ibatis控制oracle分页的问题

Your Ad Here spring、ibatis控制oracle分页的问题 - e代剑客 - BlogJava

e代剑客

生活就像海洋,只有意志坚强的人,才能到达彼岸

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  50 随笔 :: 0 文章 :: 19 评论 :: 0 Trackbacks
开发采用spring+ibatis,数据库用oracle,数据量有几千万以上,而且还要不断的增多,用了三层子查询实现分页控制

下面都只是举的例子
?1 < sqlMap? namespace ="Y_wjlx" > ?
?2
?3 ???????? < resultMap? class ="com.ctgusec.model.Y_wjlx" ?id ="y_wjlx" > ?
?4 ???????????????? < result? property ="wjbh" ?column ="wjbh" ? /> ?
?5 ???????????????? < result? property ="wjmc" ?column ="wjmc" ? /> ?
?6 ???????? </ resultMap > ?
?7 ???????? < select? id ="getAllY_wjlx" ?resultMap ="y_wjlx" > ?
?8 ???????????????? <![CDATA[ ????????????????????????
?9 ????????????????SELECT?wjbh,wjmc?FROM?(SELECT?row_.*,?rownum?rownum_?FROM?(select?wjbh,wjmc,rownum?rn?from?y_wjlx)?row_?WHERE?rownum?<=?#end#)?WHERE?rownum_?>?#start#?
10 ???????????????? ]]> ?
11 ???????? </ select > ?
12
13 </ sqlMap > ?

用了个模型基类存储分页参数,模型类可以继承此类
public ? class ?BaseModel? {?

????????
private ?Integer?start? = ? 0 ;?

????????
private ?Integer?end? = ? 30 ;?

????????
private ?Integer?size? = ? 30 ;?

????????
private ?Integer?currentPage;?

????????
private ?Integer?priviousPage;?

????????
private ?Integer?nextPage;?

????????
public ?BaseModel()? {?
????????????????
????????}
?
????????
public ?BaseModel(Integer?currentPage)? {?
????????????????
if ?(currentPage? > ? 0 )? {?
????????????????????????
this .currentPage? = ?currentPage;?
????????????????????????
this .priviousPage? = ?currentPage? - ? 1 ;?
????????????????????????
this .nextPage? = ?currentPage? + ? 1 ;?
????????????????????????
this .start? = ?priviousPage? * ?size;?
????????????????????????
this .end? = ?currentPage? * ?size;?
????????????????}
?
????????}
?

????????
// 省略geter、serter方法?
}
?

dao层:
1public?class?SqlY_wjlxDao?extends?SqlMapClientDaoSupport?implements?IY_wjlxDao?{?
2
3????????public?List?getAllY_wjlx(Y_wjlx?y_wjlx)?{?
4????????????????
5????????????????return?this.getSqlMapClientTemplate().queryForList("getAllY_wjlx",?y_wjlx);????????????????
6????????}
?
7}
?
8

控制层:spring控制类实现分页
?1 public ? class ?Y_wjlxListAllController? extends ?AbstractController? {?
?2
?3 ????????Integer?currentPage?;?
?4 ????????
?5 ???????? // y_wjlx类继承BaseModel类?
?6 ????????Y_wjlx?y_wjlx;?
?7
?8 ????????@Override?
?9 ???????? protected ?ModelAndView?handleRequestInternal(HttpServletRequest?request,?
10 ????????????????????????HttpServletResponse?response)? throws ?Exception? {?
11 ????????????????String?page? = ?request.getParameter( " page " );?
12 ???????????????? if ?(page? == ? null ? || ?page.equals( " head " ))? {?
13 ????????????????????????currentPage = 1 ;?
14 ????????????????????????y_wjlx? = ? new ?Y_wjlx(currentPage);?
15 ????????????????????????request.getSession().setAttribute( " currentPage " ,?currentPage);?
16 ????????????????}
?
17 ???????????????? if ?( " privious " .equals(page))? {?
18 ????????????????????????currentPage? = ?(Integer)?request.getSession().getAttribute( " currentPage " );?
19 ???????????????????????? if (currentPage > 1 )?currentPage? -= ? 1 ;?
20 ????????????????????????y_wjlx? = ? new ?Y_wjlx(currentPage);?
21 ????????????????????????request.getSession().setAttribute( " currentPage " ,?currentPage);?
22 ????????????????}
? else ? if ?( " next " .equals(page))? {?
23 ????????????????????????currentPage? = ?(Integer)?request.getSession().getAttribute( " currentPage " );?
24 ????????????????????????currentPage? += ? 1 ;?
25 ????????????????????????y_wjlx? = ? new ?Y_wjlx(currentPage);?
26 ????????????????????????request.getSession().setAttribute( " currentPage " ,?currentPage);?
27 ????????????????}
?
28 ????????????????List?list? = ? this .drv_Manager.getAllY_wjlx(y_wjlx);?
29 ???????????????? return ? new ?ModelAndView( " y_wjlxList " ,? " list " ,?list);?
30 ????????}
?
31
32 ???????? private ?IDrv_Manager?drv_Manager;?
33
34 ???????? public ? void ?setDrv_Manager(IDrv_Manager?drv_Manager)? {?
35 ???????????????? this .drv_Manager? = ?drv_Manager;?
36 ????????}
?
37 }

jsp页面分页调用
1 < button? onclick ="location.href??=??'y_wjlxList.shtml?page=head'" > 首&&页 </ button > ????
2 &&?
3 < button? onclick ="location.href??=??'y_wjlxList.shtml?page=privious'" > 上一页 </ button > ????
4 &&?
5 < button??? onclick ="location.href='y_wjlxList.shtml?page=next'" > 下一页 </ button >

实现了分页,而且前面的数据查询翻页效率很高,但是越到后面越慢(这个好象是没有办法的)

现在的问题是:
1、spring控制类太累赘,好象做了它不该做的事情,翻页控制有没有比较好的办法抽到服务层?
2、翻页也只有:首页、上页、下页;想把最后一页也弄出来,但是担心效率太低,首先要统计数据总数,还有就是三层子查询到了几千万数据后效率就慢了。
有没有比较好的解决办法?

posted on 2006-08-30 10:06 温柔一刀 阅读(295) 评论(8)  编辑 收藏 收藏至365Key 所属分类: 开源框架数据库相关
使用 PegaRules Process Commander V4 可能遇到的问题(1):【上一篇】
基于SSL的JavaMail:【下一篇】
【相关文章】
  • 从Domain开始看Springside
  • spring的成功j2EE案例—sun的jpetstore解析
  • oracle 日期函数
  • Sun+VxVM+Sun Cluster 9iRAC傻瓜手册[6] Oracle 安装部分
  • Rename ORACLE global_name
  • ORACLE 学习文档
  • Oracle体系
  • 使用ADO.NET存储大数据到ORACLE,文本,图象,并检索出来。
  • SpringSide 2.0 RoadMap
  • spring技术手册阅读笔记(一 ) 认识IOC
  • 【随机文章】
  • Ulra60第四遍安装为什么没有进行?
  • Remote file manager showcases embedded Linux http(
  • 把DWR的配置写到Spring的配置文件里(Spring2 新特性-自定义schema初体验)
  • Log4j深入浅出
  • CorelDRAW9高级应用之Script与预设
  • XGA,WXGA,WUXGA,和WSXGA+?
  • SharpICTCLAS分词系统简介(1)、(2)
  • EMACS 详细使用
  • VS2005+SQL2005 Reporting Service动态绑定报表(Web)
  • 三步学会Java Socket编程
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.