IBatis分页配置

IBatis分页方法我没去看,这里讲的分页为通过SQL语句来分页。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd">

<sqlMap>
	<!-- 定义别名 -->
	<typeAlias alias="user" type="com.szli.vo.EsbAdminUserInfo" />
	<typeAlias alias="pager" type="com.szli.vo.Pager" />
	
	<resultMap id="query_user_map" class="user">
		<result property="userId" column="USERID" javaType="java.lang.Long" jdbcType="NUMBER"></result>
		<result property="userName" column="USERNAME" javaType="java.lang.String" jdbcType="VARCHAR2"></result>
		<result property="passWord" column="PASSWORD" javaType="java.lang.String" jdbcType="VARCHAR2"></result>
		<result property="email" column="EMAIL" javaType="java.lang.String" jdbcType="VARCHAR2"></result>
		<result property="status" column="STATUS" javaType="java.lang.Integer" jdbcType="NUMBER"></result>
		<result property="lastLoginTime" column="LASTLOGINTIME" javaType="java.util.Date" jdbcType="DATE"></result>
		<result property="failCount" column="FAILCOUNT" javaType="java.lang.Integer" jdbcType="NUMBER"></result>
		<result property="lockTime" column="LOCKTIME" javaType="java.util.Date" jdbcType="DATE"></result>
		<result property="tenantId" column="TENANT_ID" javaType="java.lang.String" jdbcType="VARCHAR2"></result>
		<result property="skin" column="SKIN" javaType="java.lang.String" jdbcType="VARCHAR2"></result>
		<result property="userGroup.groupId" column="GROUPID" javaType="java.lang.Long" jdbcType="NUMBER"></result>
		<result property="userGroup.groupName" column="GROUPNAME" javaType="java.lang.String" jdbcType="VARCHAR2"></result>
		<result property="userGroup.status" column="STATUS" javaType="java.lang.Integer" jdbcType="NUMBER"></result>
		<result property="userGroup.description" column="DESCRIPTION" javaType="java.lang.String" jdbcType="VARCHAR2"></result>
		<result property="userGroup.groupType" column="GROUPTYPE" javaType="java.lang.Integer" jdbcType="NUMBER"></result>
	</resultMap>
	
	<select id="query_user_by_map" resultMap="query_user_map" parameterClass="java.util.HashMap">
		<![CDATA[
		SELECT * FROM (SELECT ROWNUM r,in_ui.* FROM esb_admin_user_info in_ui WHERE ROWNUM <= #ENDROWNUM#) ui,
					   esb_admin_group_info gi WHERE ui.GROUPID = gi.GROUPID AND ui.r >= #STARTROWNUM# 
		]]>	
		<isNotEmpty property="USERINFO">
			<isNotEmpty prepend="AND" property="USERINFO.userName">
				USERNAME LIKE #USERINFO.userName#
			</isNotEmpty>
			<isNotEmpty property="USERINFO.userGroup">
				<isGreaterThan prepend="AND" property="USERINFO.userGroup.groupId" compareValue="0">
					gi.GROUPID = #USERINFO.userGroup.groupId#
				</isGreaterThan>
			</isNotEmpty>
		</isNotEmpty>
	</select>
	</sqlMap>
Dao层传递过来的是一个Map集合,而Map集合中又包括查询条件与起始行‘STARTROWNUM’、总共需要多少行‘ENDROWNUM’(这两个值是由当前页与页大小算出来的:
Map<String,Object> params = new HashMap<String, Object>();
        
        params.put("USERINFO", userInfo);
        params.put("STARTROWNUM", (pageCurrent-1)*pageSize+1);
        params.put("ENDROWNUM",(pageCurrent-1)*pageSize+pageSize);
).

相关推荐