upper Page & PageResult base field to timi-java
This commit is contained in:
@ -1,8 +1,9 @@
|
|||||||
package com.imyeyu.spring.bean;
|
package com.imyeyu.spring.bean;
|
||||||
|
|
||||||
import jakarta.validation.constraints.Max;
|
import com.imyeyu.java.TimiJava;
|
||||||
import jakarta.validation.constraints.Min;
|
import com.imyeyu.java.bean.BasePage;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import com.imyeyu.utils.Text;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
@ -12,18 +13,7 @@ import java.util.LinkedHashMap;
|
|||||||
* @author 夜雨
|
* @author 夜雨
|
||||||
* @version 2023-06-02 14:47
|
* @version 2023-06-02 14:47
|
||||||
*/
|
*/
|
||||||
public class Page {
|
public class Page extends BasePage {
|
||||||
|
|
||||||
/** 下标 */
|
|
||||||
@Min(value = 0, message = "page.min_index")
|
|
||||||
protected int index = 0;
|
|
||||||
|
|
||||||
/** 数据量 */
|
|
||||||
@Max(value = 64, message = "page.max_size")
|
|
||||||
protected int size = 16;
|
|
||||||
|
|
||||||
/** 关键字 */
|
|
||||||
protected String keyword;
|
|
||||||
|
|
||||||
protected LinkedHashMap<String, BaseMapper.OrderType> orderMap;
|
protected LinkedHashMap<String, BaseMapper.OrderType> orderMap;
|
||||||
|
|
||||||
@ -31,8 +21,7 @@ public class Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Page(int index, int size) {
|
public Page(int index, int size) {
|
||||||
this.index = index;
|
super(index, size);
|
||||||
this.size = size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getOffset() {
|
public long getOffset() {
|
||||||
@ -43,30 +32,6 @@ public class Page {
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getIndex() {
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIndex(int index) {
|
|
||||||
this.index = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize() {
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSize(int size) {
|
|
||||||
this.size = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getKeyword() {
|
|
||||||
return keyword;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKeyword(String keyword) {
|
|
||||||
this.keyword = keyword;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LinkedHashMap<String, BaseMapper.OrderType> getOrderMap() {
|
public LinkedHashMap<String, BaseMapper.OrderType> getOrderMap() {
|
||||||
return orderMap;
|
return orderMap;
|
||||||
}
|
}
|
||||||
@ -75,8 +40,13 @@ public class Page {
|
|||||||
this.orderMap = orderMap;
|
this.orderMap = orderMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addOrder(String field, BaseMapper.OrderType orderType) {
|
||||||
|
orderMap = TimiJava.firstNotNull(orderMap, new LinkedHashMap<>());
|
||||||
|
orderMap.put(Text.camelCase2underscore(field), orderType);
|
||||||
|
}
|
||||||
|
|
||||||
public static <T, P extends Page, R extends PageResult<T>> R toResult(BaseMapper<T, ?> pageMapper, P page, R result) {
|
public static <T, P extends Page, R extends PageResult<T>> R toResult(BaseMapper<T, ?> pageMapper, P page, R result) {
|
||||||
result.setList(pageMapper.list(page.getOffset(), page.getLimit()));
|
result.setList(pageMapper.listOrder(page.getOffset(), page.getLimit(), page.getOrderMap()));
|
||||||
result.setTotal(pageMapper.count());
|
result.setTotal(pageMapper.count());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
package com.imyeyu.spring.bean;
|
package com.imyeyu.spring.bean;
|
||||||
|
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.bean.BasePageResult;
|
||||||
import com.imyeyu.utils.Calc;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 抽象页面查询结果
|
* 抽象页面查询结果
|
||||||
@ -11,49 +8,5 @@ import java.util.List;
|
|||||||
* @author 夜雨
|
* @author 夜雨
|
||||||
* @version 2023-06-02 14:47
|
* @version 2023-06-02 14:47
|
||||||
*/
|
*/
|
||||||
public class PageResult<T> {
|
public class PageResult<T> extends BasePageResult<T> {
|
||||||
|
|
||||||
/** 总数据量 */
|
|
||||||
protected long total;
|
|
||||||
|
|
||||||
/** 总页数 */
|
|
||||||
protected int pages;
|
|
||||||
|
|
||||||
protected List<T> list;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取总数据量
|
|
||||||
*
|
|
||||||
* @return 总数据量
|
|
||||||
*/
|
|
||||||
public long getTotal() {
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置总数据量
|
|
||||||
*
|
|
||||||
* @param total 总数据量
|
|
||||||
*/
|
|
||||||
public void setTotal(long total) {
|
|
||||||
this.total = total;
|
|
||||||
if (TimiJava.isNotEmpty(list)) {
|
|
||||||
pages = Calc.ceil(1D * total / list.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<T> getList() {
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setList(List<T> list) {
|
|
||||||
this.list = list;
|
|
||||||
if (TimiJava.isNotEmpty(list)) {
|
|
||||||
pages = Calc.ceil(1D * total / list.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPages() {
|
|
||||||
return pages;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user