public
Page<T> page(QueryBuilder queryBuilder,
Date
lastEndCreateTime, Integer lastEndCount, Integer lastEndOffset,
int offset, int limit) {
FromBuilder fromBuilder = queryBuilder.from(getModelClass());
Page<T> page =
new
Page<>();
int
count
= dao.
count
(fromBuilder);
page.setTotal(
count
);
if
(
count
== 0) {
return
page;
}
if
(offset == 0 || lastEndCreateTime == null || lastEndCount == null || lastEndOffset == null) {
List<T> list = dao.find(
SelectBuilder.selectFrom(fromBuilder.offsetLimit(offset, limit).order().desc(
"createTime"
).
end
()));
page.setData(list);
return
page;
}
boolean isForward = offset >= lastEndOffset;
if
(isForward) {
int calcOffset = offset - lastEndOffset + lastEndCount;
int calcOffsetFormEnd =
count
- offset - limit;
if
(calcOffsetFormEnd <= calcOffset) {
isForward = false;
if
(calcOffsetFormEnd > 0) {
fromBuilder.order().asc(
"createTime"
).
end
().offsetLimit(calcOffsetFormEnd, limit);
}
else
{
fromBuilder.order().asc(
"createTime"
).
end
().offsetLimit(0, calcOffsetFormEnd + limit);
}
}
else
{
fromBuilder.where().andLe(
"createTime"
, lastEndCreateTime).
end
().order().desc(
"createTime"
).
end
()
.offsetLimit(calcOffset, limit);
}
}
else
{
fromBuilder.where().andGe(
"createTime"
, lastEndCreateTime).
end
().order().asc(
"createTime"
).
end
()
.offsetLimit(lastEndOffset - offset - limit - 1 + lastEndCount, limit);
}
List<T> list = dao.find(SelectBuilder.selectFrom(fromBuilder));
if
(!isForward) {
list.sort(
new
Comparator<T>() {
@Override
public
int compare(T o1, T o2) {
return
o1.getCreateTime().before(o2.getCreateTime()) ? 1 : -1;
}
});
}
page.setData(list);
return
page;
}### #### ##前端js參數,基於bootstrap table###<pre
class
=
"brush:php;toolbar:false"
> this.lastEndCreateTime = null;
this.currentEndCreateTime = null;
this.isRefresh = false;
this.currentEndOffset = 0;
this.lastEndOffset = 0;
this.lastEndCount = 0;
this.currentEndCount = 0;
$(
"#"
+ this.tableId).bootstrapTable({
url: url,
method:
'get'
,
contentType:
"application/x-www-form-urlencoded"
,
dataType:
"json"
,
dataField:
"data"
,
pagination: true,
sidePagination:
"server"
,
pageList: [10, 25, 50, 100, 200],
search: true,
showRefresh: true,
toolbar:
"#"
+ tableId +
"Toolbar"
,
iconSize:
"outline"
,
icons: {
refresh:
"icon fa-refresh"
,
},
queryParams:
function
(params){
if
(params.offset == 0){
this.currentEndOffset = params.offset + params.limit;
}
else
{
if
(params.offset + params.limit==this.currentEndOffset){
this.isRefresh = true;
params.lastEndCreateTime = this.lastEndCreateTime;
params.lastEndOffset = this.lastEndOffset;
params.lastEndCount = this.lastEndCount;
}
else
{
console.log(this.currentEndCount);
this.isRefresh = false;
params.lastEndCreateTime = this.currentEndCreateTime;
params.lastEndOffset = this.currentEndOffset;
params.lastEndCount = this.currentEndCount;
this.lastEndOffset = this.currentEndOffset;
this.currentEndOffset = params.offset + params.limit;
console.log(params.lastEndOffset+
","
+params.lastEndCreateTime);
}
}
return
params;
},
onSearch:
function
(text) {
this.keyword = text;
},
onPostBody : onPostBody,
onLoadSuccess:
function
(resp) {
if
(resp.code!=0){
alertUtils.error(resp.msg);
}
var
data = resp.data;
var
dateLength = data.length;
if
(dateLength==0){
return
;
}
if
(!this.isRefresh){
this.lastEndCreateTime = this.currentEndCreateTime;
this.currentEndCreateTime = data[data.length-1].createTime;
this.lastEndCount = this.currentEndCount;
this.currentEndCount = 0;
for
(
var
i = 0; i < resp.data.length; i++) {
var
item = resp.data[i];
if
(item.createTime === this.currentEndCreateTime){
this.currentEndCount++;
}
}
}
}
});