Benefit of this type of paging is that it doesn't load all the results up front. Useful for very large result sets. I'm a fan of MyBatis, so this example below demonstrates the use with MyBatis.
ZUL
<paging id="executionsPaging"
onCreate="executionsList.setPaginal(self)"
totalSize="@bind(vm.executionsTotalSize)"
pageSize="@bind(vm.executionsPageSize)"
activePage="@bind(vm.currentPageNumber)"
onPaging="@command('pageExecutions', pageNum=event.activePage)"
/>
<listbox id="executionsList" model="@load(vm.executions)"
selectedItem="@bind(vm.selectedExecution)".... />
Executions ViewModel
public class ExecutionsVM {
private final static Logger logger = LoggerFactory.getLogger(ExecutionsVM.class);
private List executions = new ArrayList();
private ExecutionSearchFilter searchFilter = new ExecutionSearchFilter();
private long executionsTotalSize = 0l;
private int executionsPageSize = 25;
private int currentPageNumber = 0;
@WireVariable
private ExecutionService executionService;
@NotifyChange({"executions","executionsTotalSize"})
@Command
public void pageExecutions(@BindingParam("pageNum") int pageNum) {
logger.debug("pageExecutions for pagNum {}", pageNum);
this.currentPageNumber = pageNum;
populateSearchFilter();
executions = executionService.getExecutions(searchFilter);
executionsTotalSize = executionService.getExecutionsSize(searchFilter);
}
private void populateSearchFilter() {
int base = this.currentPageNumber * executionsPageSize;
int firstRow = base + 1;
int lastRow = base + executionsPageSize;
searchFilter.setLowerRowLimit(firstRow);
searchFilter.setUpperRowLimit(lastRow);
}
}
Executions Service (wraps Mapper)
@Service
public class ExecutionService {
@Resource
private ExecutionMapper executionMapper;
public List featchExecutions(ExecutionSearchFilter searchFilter) {
return executionMapper.getExecutions(searchFilter);
}
}
Executions Mapper
public interface ExecutionMapper {
List featchExecutions(ExecutionSearchFilter searchFilter)
}
Search Filter POJO
public class ExecutionSearchFilter {
private int upperRowLimit;
private int lowerRowLimit;
//setters/getters
}
Executions Mapper MXL
<select id="getExecutions" resultMap="executionResultMap" parameterType="ExecutionSearchFilter">
select
EXECUTION_ID,
EXECUTION_NM,
ROW_NUM
FROM
(
SELECT
tempRow.EXECUTION_ID,
tempRow.EXECUTION_NM,
rownum ROW_NUM
from
(
SELECT
e.EXECUTION_ID,
e.EXECUTION_NM
FROM
EXECUTION_T e
) tempRow
WHERE
rownum <![CDATA[ <= ]]> #{upperRowLimit}
)
WHERE
ROW_NUM >= #{lowerRowLimit}
</select>