1
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
方式一: 调用它的分页方法:List result = sqlMapClient.queryForList(sqlid, parameterObject, begin, length); 方式二: 利用不同数据库的特点,把分页的条件作为参数传进去,在SQL语句处拼接。如MYSQL数据库可以使用它的limit函数。 比较:方式二比较通用,只需调用相同的方法,即可实现分页或者不分页,此时分页的参数只是做为普通的参数。 方式一比较简单,在SQL语句处无需关注分页的问题,ibatis会自动帮你分页(因为你调用了它的分页方法)。 示例代码: 方式一的代码: Map parameterObject= new HashMap(); String sqlid= "address.getAddressList" ; int begin= 0 ; int length= 25 List result = sqlMapClient.queryForList(sqlid, parameterObject, begin, length); <select id= "getAddressList" parameterClass= "java.util.HashMap" resultClass= "last.soul.common.beans.Address" > select id, username, name, sex, mobile, email, qq, company, address, postcode from address </select> 方式二的代码: Map parameterObject= new HashMap(); parameterObject.put( "orderByClause" , "username asc" ); parameterObject.put( "limimitClauseStart" , startIndex); parameterObject.put( "litClauseCount" , pageSize); String sql= "address.getAddressList" ; List result = sqlMapClient.queryForList(sql, parameterObject); <select id= "getAddressList" parameterClass= "java.util.HashMap" resultClass= "last.soul.common.beans.Address" > select id, username, name, sex, mobile, email, qq, company, address, postcode from address <isParameterPresent> <isNotNull property= "orderByClause" > order by $orderByClause$ </isNotNull> <isNotNull property= "limitClauseStart" > limit $limitClauseStart$, $limitClauseCount$ </isNotNull> </isParameterPresent> </select> |