89 lines
2.5 KiB
Java
89 lines
2.5 KiB
Java
package com.zhgd.xmgl.util;
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import lombok.experimental.UtilityClass;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
|
|
@UtilityClass
|
|
public class PageUtil {
|
|
|
|
public Page getPage(Map<String, Object> map) {
|
|
int pageNo = Integer.parseInt(map.getOrDefault("pageNo", 1).toString());
|
|
int pageSize = Integer.parseInt(map.getOrDefault("pageSize", 10).toString());
|
|
return new Page(pageNo, pageSize);
|
|
}
|
|
|
|
|
|
/**
|
|
* MyBatis-Plus page属性复制
|
|
*
|
|
* @param sourcePage sourcePage
|
|
* @param clazz clazz
|
|
* @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<T>
|
|
* @author myyan
|
|
* @date 2022/12/22 15:19
|
|
*/
|
|
public static <T> Page<T> copyProperties(Page<?> sourcePage, Class<T> clazz) {
|
|
if (sourcePage == null) {
|
|
return null;
|
|
}
|
|
|
|
Page<T> result = new Page<T>();
|
|
result.setRecords(copyProperties(sourcePage.getRecords(), clazz));
|
|
result.setTotal(sourcePage.getTotal());
|
|
result.setSize(sourcePage.getSize());
|
|
result.setCurrent(sourcePage.getCurrent());
|
|
result.setOrders(sourcePage.getOrders());
|
|
result.setSearchCount(sourcePage.isSearchCount());
|
|
result.setOptimizeCountSql(sourcePage.optimizeCountSql());
|
|
result.setHitCount(sourcePage.isHitCount());
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* List集合复制
|
|
*
|
|
* @param sourcesList sourcesList
|
|
* @param target target
|
|
* @return java.util.List<T>
|
|
* @author myyan
|
|
* @date 2022/12/22 15:18
|
|
*/
|
|
public static <T> List<T> copyProperties(List<?> sourcesList, Class<T> target) {
|
|
if (sourcesList == null) {
|
|
return null;
|
|
}
|
|
return sourcesList.stream().map(item -> copyProperties(item, target)).collect(Collectors.toList());
|
|
}
|
|
|
|
/**
|
|
* 对象复制
|
|
*
|
|
* @param source source
|
|
* @param clazz class
|
|
* @return T
|
|
* @author myyan
|
|
* @date 2022/12/22 15:15
|
|
*/
|
|
public static <T> T copyProperties(Object source, Class<T> clazz) {
|
|
if (source == null) {
|
|
return null;
|
|
}
|
|
if (clazz == null) {
|
|
return null;
|
|
}
|
|
T result = null;
|
|
try {
|
|
result = clazz.newInstance();
|
|
} catch (InstantiationException | IllegalAccessException e) {
|
|
e.printStackTrace();
|
|
}
|
|
BeanUtil.copyProperties(source, result);
|
|
return result;
|
|
}
|
|
}
|