首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

spring、ibatis控制oracle分页的有关问题

2012-11-18 
spring、ibatis控制oracle分页的问题开发采用spring+ibatis,数据库用oracle,数据量有几千万以上,而且还要不

spring、ibatis控制oracle分页的问题
开发采用spring+ibatis,数据库用oracle,数据量有几千万以上,而且还要不断的增多,用了三层子查询实现分页控制

下面都只是举的例子

<sqlMap namespace="Y_wjlx"><resultMap id="y_wjlx"><result property="wjbh" column="wjbh" /><result property="wjmc" column="wjmc" /></resultMap><select id="getAllY_wjlx" resultMap="y_wjlx"><![CDATA[SELECT wjbh,wjmc FROM (SELECT row_.*, rownum rownum_ FROM (select wjbh,wjmc,rownum rn from y_wjlx) row_ WHERE rownum <= #end#) WHERE rownum_ > #start#]]></select></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层:

public class SqlY_wjlxDao extends SqlMapClientDaoSupport implements IY_wjlxDao {public List getAllY_wjlx(Y_wjlx y_wjlx) {return this.getSqlMapClientTemplate().queryForList("getAllY_wjlx", y_wjlx);}}


控制层:spring控制类实现分页

public class Y_wjlxListAllController extends AbstractController {Integer currentPage ;//y_wjlx类继承BaseModel类Y_wjlx y_wjlx;@Overrideprotected ModelAndView handleRequestInternal(HttpServletRequest request,HttpServletResponse response) throws Exception {String page = request.getParameter("page");if (page == null || page.equals("head")) {currentPage=1;y_wjlx = new Y_wjlx(currentPage);request.getSession().setAttribute("currentPage", currentPage);}if ("privious".equals(page)) {currentPage = (Integer) request.getSession().getAttribute("currentPage");if(currentPage>1) currentPage -= 1;y_wjlx = new Y_wjlx(currentPage);request.getSession().setAttribute("currentPage", currentPage);} else if ("next".equals(page)) {currentPage = (Integer) request.getSession().getAttribute("currentPage");currentPage += 1;y_wjlx = new Y_wjlx(currentPage);request.getSession().setAttribute("currentPage", currentPage);}List list = this.drv_Manager.getAllY_wjlx(y_wjlx);return new ModelAndView("y_wjlxList", "list", list);}private IDrv_Manager drv_Manager;public void setDrv_Manager(IDrv_Manager drv_Manager) {this.drv_Manager = drv_Manager;}}


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



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

现在的问题是:
1、spring控制类太累赘,好象做了它不该做的事情,翻页控制有没有比较好的办法抽到服务层?
2、翻页也只有:首页、上页、下页;想把最后一页也弄出来,但是担心效率太低,首先要统计数据总数,还有就是三层子查询到了几千万数据后效率就慢了。
有没有比较好的解决办法?public class Page {private Integer currentPage;private Integer priviousPage;private Integer nextPage;private Integer totalPage;public Page(Integer currentPage); {this.currentPage = currentPage;this.priviousPage = currentPage - 1;this.nextPage = currentPage + 1;//省略其它逻辑...}//省略setter,getter...}
在类中,处理分页的逻辑。

在DAO类中传入Page实例来构建查询条件。这样可以不涉及到模型层。

2.要有总页数,count是难免的,所以只有自己权衡是否有需要。一但有总记录数,分页就可以做到很灵活,比如自由设定一页的记录数和跳到第几页。public class Page {private Integer currentPage;private Integer priviousPage;private Integer nextPage;private Integer totalPage;public Page(Integer currentPage); {this.currentPage = currentPage;this.priviousPage = currentPage - 1;this.nextPage = currentPage + 1;//省略其它逻辑...}//省略setter,getter...}
在类中,处理分页的逻辑。
在DAO类中传入Page实例来构建查询条件。这样可以不涉及到模型层。


我试着改了下,您再看下,但是感觉非得在控制层保留session才可以,控制层还是很累赘。在DAO类中传入Page实例来构建查询条件好象也不能避免在控制层使用session,能提供点具体的么?

热点排行