开发采用spring+ibatis,数据库用oracle,数据量有几千万以上,而且还要不断的增多,用了三层子查询实现分页控制
下面都只是举的例子
下面都只是举的例子
< 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" >
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 >
用了个模型基类存储分页参数,模型类可以继承此类
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" >
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方法
}
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层:
1
public
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
2
3 public List getAllY_wjlx(Y_wjlx y_wjlx) {
4
5 return this.getSqlMapClientTemplate().queryForList("getAllY_wjlx", y_wjlx);
6 }
7}
8
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 }
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 >
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、翻页也只有:首页、上页、下页;想把最后一页也弄出来,但是担心效率太低,首先要统计数据总数,还有就是三层子查询到了几千万数据后效率就慢了。
有没有比较好的解决办法?
引用:http://www.blogjava.net/ctguzhupan/archive/2006/08/30/66580.aspx