mysql分頁-limit offset分頁

ZHOU_VIP發表於2019-03-08
//每頁顯示多少條資料
String batchVal = request.getParameter("numPerpage");
//頁碼
String offsetVal = request.getParameter("page");
batchVal = (batchVal == null || batchVal.trim().equals("")) ? "10" : batchVal.trim();
offsetVal = (offsetVal == null || offsetVal.trim().equals("")) ? "1" : offsetVal.trim();
DoorGuardPersonQry cond = new DoorGuardPersonQry();
cond.setBatch(Integer.parseInt(batchVal));
cond.setOffset((Integer.parseInt(offsetVal)-1)*(Integer.parseInt(batchVal)));

<select id="queryDoorGuardPerson" resultMap="BaseResultMap" >
	 SELECT          PERSONID,
			 NAME,
			 IDCARD, 
			 SEX,
			 AGE,
			 JOB,
			 DEPARTMENT,
			 BIRTHDAY,
			 ADDR,
			 TELEPHONE,
			 EMAIL,
			 EDU,
			 FLAG,
			 PHOTO,
			 AREAID,
			 PROJECTID,
			 REMARK  
	   FROM t_doorguard_person
	  WHERE 1 = 1 
	  <if test='p.personid != null and p.personid != "" '>
		 AND PERSONID = #{p.personid, jdbcType=VARCHAR} 
	  </if>
	  <if test='p.name != null and p.name != "" '>
		 AND NAME like CONCAT('%',#{p.name, jdbcType=VARCHAR},'%')
	  </if>
	  <if test='p.flag != null and p.flag != ""'>
		 AND FLAG = #{p.flag, jdbcType=VARCHAR} 
	  </if>
	  <if test='p.idcard != null and p.idcard != "" '>
		 AND IDCARD = #{p.idcard, jdbcType=VARCHAR} 
	  </if>
	  <if test='p.department != null and p.department != "" '>
		 AND DEPARTMENT like CONCAT('%',#{p.department, jdbcType=VARCHAR},'%')
	  </if>
	  ORDER BY PERSONID ASC 
	  LIMIT #{p.batch, jdbcType=INTEGER} OFFSET #{p.offset, jdbcType=INTEGER} 
</select>

https://blog.csdn.net/czh500/article/details/86270424

https://blog.csdn.net/tigerhu256/article/details/78902791

相關文章