開發(fā)采用spring+ibatis,數(shù)據(jù)庫用oracle,數(shù)據(jù)量有幾千萬以上,而且還要不斷的增多,用了三層子查詢實現(xiàn)分頁控制
下面都只是舉的例子
用了個模型基類存儲分頁參數(shù),模型類可以繼承此類
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層:
控制層:spring控制類實現(xiàn)分頁
jsp頁面分頁調(diào)用
實現(xiàn)了分頁,而且前面的數(shù)據(jù)查詢翻頁效率很高,但是越到后面越慢(這個好象是沒有辦法的)
現(xiàn)在的問題是:
1、spring控制類太累贅,好象做了它不該做的事情,翻頁控制有沒有比較好的辦法抽到服務(wù)層?
2、翻頁也只有:首頁、上頁、下頁;想把最后一頁也弄出來,但是擔(dān)心效率太低,首先要統(tǒng)計數(shù)據(jù)總數(shù),還有就是三層子查詢到了幾千萬數(shù)據(jù)后效率就慢了。
有沒有比較好的解決辦法?
下面都只是舉的例子
?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
>
?

?2

?3

?4

?5

?6

?7

?8

?9

10

11

12

13


用了個模型基類存儲分頁參數(shù),模型類可以繼承此類






































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



4

5

6

7

8

控制層:spring控制類實現(xiàn)分頁
?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

?4

?5

?6

?7

?8

?9

10



11

12



13

14

15

16

17



18

19

20

21

22



23

24

25

26

27

28

29

30

31

32

33

34



35

36

37

jsp頁面分頁調(diào)用
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

4

5

實現(xiàn)了分頁,而且前面的數(shù)據(jù)查詢翻頁效率很高,但是越到后面越慢(這個好象是沒有辦法的)
現(xiàn)在的問題是:
1、spring控制類太累贅,好象做了它不該做的事情,翻頁控制有沒有比較好的辦法抽到服務(wù)層?
2、翻頁也只有:首頁、上頁、下頁;想把最后一頁也弄出來,但是擔(dān)心效率太低,首先要統(tǒng)計數(shù)據(jù)總數(shù),還有就是三層子查詢到了幾千萬數(shù)據(jù)后效率就慢了。
有沒有比較好的解決辦法?