分页处理
1.自定义分页查询
import java.io.Serializable;
public class PageReq implements Serializable {
/**
* 当前页
*/
private Integer current;
/**
* 分页偏移量
*/
private Integer offSet;
/**
* 每页条数
*/
private Integer pageSize;
public Integer getOffSet() {
return ((current == null || current < 1 ? 1 : current) - 1) * (pageSize == null ? 20 : pageSize);
}
public Integer getCurrent() {
if (current == null) {
current = 1;
}
return current;
}
public void setCurrent(Integer current) {
this.current = current;
}
public Integer getPageSize() {
if (pageSize == null) {
pageSize = 20;
}
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
}
xml里使用方式
<select id="pageSchoolsAndUser" resultType="mode.vo.SchoolInfoVO">
SELECT t1.school_id schoolId,
t1.school_name schoolName,
t2.USH014 schoolHeader,
t1.signed_grade_number signedGradeNumber,
t1.signed_class_number signedClassNumber,
t1.status
FROM tb_school_info t1
LEFT JOIN szush t2 ON t1.headmaster_id = t2.USH001
LIMIT #{offSet}, #{pageSize}
</select>
2.针对自动分页处理任务场景
@Test
public void selectBatch() {
// 查询总条数
int totalCount = 10000;
// 每次查询条数
int queryBatchCount = 1000;
// 已经查询的条数
int passCount = 0;
do {
System.out.println("select * from a limit " + passCount + "," + queryBatchCount);
passCount = queryBatchCount + passCount;
} while (passCount <= totalCount);
}

浙公网安备 33010602011771号