一、BeanUtil.Class
package com.supcon.mare.tankinfo.util;
import com.alibaba.excel.util.CollectionUtils;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
/**
* @author: zhaoxu
* @description:
*/
public class BeanUtil {
/**
* 通过方法名动态执行某个方法
*
* @param object
* @param methodName
* @param parameters
* @return
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws NoSuchMethodException
*/
public static Object executeMethod(Object object, String methodName, Object... parameters) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
Class<?> clazz = object.getClass();
ArrayList<Class<?>> paramTypeList = new ArrayList<>();
for (Object paramType : parameters) {
paramTypeList.add(paramType.getClass());
}
Class<?>[] classArray = new Class[paramTypeList.size()];
Method method = clazz.getMethod(methodName, paramTypeList.toArray(classArray));
Object invoke = method.invoke(object, parameters);
return invoke;
}
/**
* 获取所有属性值
*
* @return
* @throws IllegalAccessException
*/
public static Map<String, Object> getFieldsValue(Object object) throws IllegalAccessException {
Class<?> clazz = object.getClass();
Map<String, Object> fieldValuesMap = new HashMap<>(16);
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
Object fieldValue = field.get(object);
fieldValuesMap.put(field.getName(), fieldValue);
}
return fieldValuesMap;
}
/**
* 设置属性值
*
* @param property
* @param value
*/
public static Boolean setValue(Object object, String property, Object value) {
Class<?> clazz = object.getClass();
try {
Field declaredField = clazz.getDeclaredField(property);
declaredField.setAccessible(true);
declaredField.set(object, value);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
return true;
}
/**
* 获取对象所有属性及对应的类别
*
* @param object
* @return
* @throws IllegalAccessException
*/
public static Map<String, Class<?>> getFields(Object object) throws IllegalAccessException {
Class<?> clazz = object.getClass();
Map<String, Class<?>> attrMap = new HashMap<>(16);
if (clazz != null) {
Iterator<String> iterator = getValues(object).keySet().iterator();
while (iterator.hasNext()) {
attrMap.put(iterator.next(), Object.class);
}
}
return attrMap;
}
/**
* 获取所有属性值
*
* @return
* @throws IllegalAccessException
*/
public static Map<String, Object> getValues(Object object) throws IllegalAccessException {
Map<String, Object> fieldValuesMap = new HashMap<>(16);
Class<?> clazz = object.getClass();
if (clazz != null) {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
Object fieldValue = field.get(object);
fieldValuesMap.put(field.getName(), fieldValue);
}
return fieldValuesMap;
}
return fieldValuesMap;
}
/**
* 获取拥有指定注解的字段
*
* @param objectClass
* @param annoClass
* @return
*/
public static List<Field> getTargetAnnoation(Class<?> objectClass, Class<? extends Annotation> annoClass) {
List<Field> fields = new ArrayList<>();
Field[] declaredFields = objectClass.getDeclaredFields();
for (Field field : declaredFields) {
field.setAccessible(true);
if (!field.isAnnotationPresent(annoClass)) {
continue;
} else {
fields.add(field);
}
}
if (!CollectionUtils.isEmpty(fields)) {
return fields;
} else {
return null;
}
}
}
二、ListUtil.Class
package com.supcon.mare.tankinfo.util;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author: zhaoxu
* @description:
*/
public class ListUtil {
/**
* 列表转为字符串
*
* @param data 数据
* @param split 分隔符
* @return 字符串
*/
public static String joinList(List data, String split) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < data.size(); i++) {
Object item = data.get(i);
//跳过null值
if (item != null) {
result.append(item.toString());
//如果不是最后一个
if (i + 1 < data.size()) {
result.append(split);
}
}
}
return result.toString();
}
/**
* 字符串转为list
*
* @param data 数据
* @param split 切割符号
* @return 列表
*/
public static List<String> splitIntoList(String data, String split) {
//为空
if (data == null) {
return null;
}
String[] splitArray = data.split(split);
if (splitArray.length > 0) {
List<String> resultList = new ArrayList<>();
for (String item : splitArray) {
//自动跳过空值
if (item != null && !"".equals(item)) {
resultList.add(item);
}
}
return resultList;
} else {
return null;
}
}
/**
* 分页
*
* @param data 数据
* @param current 页数
* @param pageSize 每页条数
* @return map
*/
public static <E> Map<String, Object> toPage(List<E> data, int current, int pageSize) {
//判空
if (data == null || data.size() <= 0) {
return null;
}
Map<String, Object> destMap = new HashMap<>(4);
List<E> pageList = data.stream()
.skip((current - 1) * pageSize)
.limit(pageSize)
.collect(Collectors.toList());
//分页需要的参数
destMap.put("list", pageList);
destMap.put("current", current);
destMap.put("pageSize", pageSize);
destMap.put("total", data.size());
return destMap;
}
/**
* 查找在列表1中列表2中没有的元素
* @param list1 列表1
* @param list2 列表2
* @param <E> 泛型
* @return 差异列表
*/
public static <E> List<E> getListDiff(List<E> list1, List<E> list2) {
if (list1 == null || list1.isEmpty()) {
return list2 == null || list2.isEmpty() ? new ArrayList<>() : list2;
}
if (list2 == null || list2.isEmpty()) {
return list1 == null || list1.isEmpty() ? new ArrayList<>() : list1;
}
Set<E> diffSet = new HashSet<>(list1);
Set<E> setOfCommonElements = new HashSet<>(list2);
//先把列表2全部加进来
diffSet.addAll(list2);
//调用方法保留共有元素
setOfCommonElements.retainAll(list1);
//移除共有的
diffSet.removeAll(setOfCommonElements);
return new ArrayList<>(diffSet);
}
}
三、MapUtil.Class
package com.supcon.mare.oms.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
/**
* @author ZhaoXu
* @date 2021/11/12 14:24
*/
public class MapUtil {
@FunctionalInterface
/**
* 内部接口
*/
public interface Comparetor<T> {
/**
* 比较函数
*
* @param o1
* @param o2
* @return
*/
Boolean compare(T o1, T o2);
}
/**
* 过滤map
*
* @param map
* @param predicate
* @return
*/
public static <T> Map<String, T> filter(Map<String, T> map, Predicate<Map.Entry<String, T>> predicate) {
Map<String, T> newMap = new HashMap<>(8);
for (Map.Entry<String, T> entry : map.entrySet()) {
//按照自定义规则过滤
String key = entry.getKey();
T value = entry.getValue();
//调用test方法
if (predicate.test(entry)) {
newMap.put(key, value);
}
}
return newMap;
}
/**
* map排序
*
* @param map
* @param comparator lambda自定义比较条件
* @param <T>
* @return
*/
public static <T> List<Map.Entry<String, T>> sort(Map<String, T> map, Comparetor<Map.Entry<String, T>> comparator) {
//先存到列表,好做处理
List<Map.Entry<String, T>> resultList = new ArrayList<>();
resultList.addAll(map.entrySet());
quickSort(resultList, 0, map.size() - 1, comparator);
return resultList;
}
/**
* 快排
*
* @param a
* @param start
* @param end
*/
public static <L> void quickSort(List<L> a, int start, int end, Comparetor<L> comparator) {
if (a.size() < 0) {
return;
}
if (start >= end) {
return;
}
int left = start;
int right = end;
L temp = a.get(left);
while (left < right) {
//从右面找
while (left < right && comparator.compare(a.get(right), temp)) {
right--;
}
//从左面找
a.set(left, a.get(right));
while (left < right && !comparator.compare(a.get(left), temp)) {
left++;
}
//把坑填上
a.set(right, a.get(left));
}
a.set(left, temp);
quickSort(a, start, left - 1, comparator);
quickSort(a, left + 1, end, comparator);
}
/**
* 按照正序排序
*
* @param entry1
* @param entry2
* @param <T>
* @return
*/
public static <T> Boolean ascByValue(Map.Entry<String, T> entry1, Map.Entry<String, T> entry2) {
return entry1.getValue().toString().compareTo(entry2.getValue().toString()) >= 0;
}
/**
* 按照倒序排序
*
* @param entry1
* @param entry2
* @param <T>
* @return
*/
public static <T> Boolean descByValue(Map.Entry<String, T> entry1, Map.Entry<String, T> entry2) {
return entry1.getValue().toString().compareTo(entry2.getValue().toString()) <= 0;
}
/**
* 按照正序排序
*
* @param entry1
* @param entry2
* @param <T>
* @return
*/
public static <T> Boolean ascByKey(Map.Entry<String, T> entry1, Map.Entry<String, T> entry2) {
return entry1.getKey().compareTo(entry2.getKey()) >= 0;
}
/**
* 按照倒序排序
*
* @param entry1
* @param entry2
* @param <T>
* @return
*/
public static <T> Boolean descByKey(Map.Entry<String, T> entry1, Map.Entry<String, T> entry2) {
return entry1.getKey().compareTo(entry2.getKey()) <= 0;
}
}
四、ChineseHelper.Class
pom文件:
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.1</version>
</dependency>
package com.supcon.mare.tankinfo.util;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 一些中文的操作
*/
public final class ChineseHelper {
public static final Pattern PATTERN_CHINESE_BY_REG =Pattern.compile("[\\u4E00-\\u9FBF]+");
public static final Pattern PATTERN_CHINESE =Pattern.compile("[\u4E00-\u9FA5]+");
public static final Pattern PATTERN_MESSY_CODE =Pattern.compile("\\s*|\t*|\r*|\n*");
/**
* 将字符串中的中文转化为拼音,其他字符不变
*
* @param inputString
* @return
*/
public static String getPingYin(String inputString) {
HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
format.setVCharType(HanyuPinyinVCharType.WITH_V);
char[] input = inputString.trim().toCharArray();
String output = "";
try {
for (int i = 0; i < input.length; i++) {
if (java.lang.Character.toString(input[i]).matches("[\\u4E00-\\u9FA5]+")) {
String[] temp = PinyinHelper.toHanyuPinyinStringArray(input[i], format);
output += temp[0];
} else{
output += java.lang.Character.toString(input[i]);
}
}
} catch (BadHanyuPinyinOutputFormatCombination e) {
e.printStackTrace();
}
return output;
}
/**
* 获取汉字串拼音首字母,英文字符不变
*
* @param chinese 汉字串
* @return 汉语拼音首字母
*/
public static String getFirstSpell(String chinese) {
StringBuilder pybf = new StringBuilder();
char[] arr = chinese.toCharArray();
HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
for (int i = 0; i < arr.length; i++) {
if (arr[i] > 128) {
try {
String[] temp = PinyinHelper.toHanyuPinyinStringArray(arr[i], defaultFormat);
if (temp != null) {
pybf.append(temp[0].charAt(0));
}
} catch (BadHanyuPinyinOutputFormatCombination e) {
e.printStackTrace();
}
} else {
pybf.append(arr[i]);
}
}
return pybf.toString().replaceAll("\\W", "").trim();
}
/**
* 获取汉字串拼音,英文字符不变
*
* @param chinese 汉字串
* @return 汉语拼音
*/
public static String getFullSpell(String chinese) {
StringBuffer pybf = new StringBuffer();
char[] arr = chinese.toCharArray();
HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
for (int i = 0; i < arr.length; i++) {
if (arr[i] > 128) {
try {
pybf.append(PinyinHelper.toHanyuPinyinStringArray(arr[i], defaultFormat)[0]);
} catch (BadHanyuPinyinOutputFormatCombination e) {
e.printStackTrace();
}
} else {
pybf.append(arr[i]);
}
}
return pybf.toString();
}
/**
* 只能判断部分CJK字符(CJK统一汉字)
* @param str
* @return
*/
public static boolean isChineseByReg(String str) {
if (str == null) {
return false;
}
return PATTERN_CHINESE_BY_REG.matcher(str.trim()).find();
}
// 只能判断部分CJK字符(CJK统一汉字)
public static boolean isChineseByName(String str) {
if (str == null) {
return false;
}
// 大小写不同:\\p 表示包含,\\P 表示不包含
// \\p{Cn} 的意思为 Unicode 中未被定义字符的编码,\\P{Cn} 就表示 Unicode中已经被定义字符的编码
String reg = "\\p{InCJK Unified Ideographs}&&\\P{Cn}";
Pattern pattern = Pattern.compile(reg);
return pattern.matcher(str.trim()).find();
}
/**
* 完整的判断中文汉字和符号
* @param strName
* @return
*/
public static boolean isChinese(String strName) {
char[] ch = strName.toCharArray();
for (int i = 0; i < ch.length; i++) {
char c = ch[i];
if (isChinese(c)) {
return true;
}
}
return false;
}
/**
* 判断是否是中文
*
* @param c
* @return
*/
public static boolean isChinese(char c) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
return true;
}
return false;
}
/**
* 获取一个字符串中中文字符的个数
*/
public static int chineseLength(String str) {
Matcher m = PATTERN_CHINESE.matcher(str);
int i = 0;
while (m.find()) {
String temp = m.group(0);
i += temp.length();
}
return i;
}
/**
* 判断是否是乱码
*
* @param strName
* @return
*/
public static float isMessyCode(String strName) {
Matcher m = PATTERN_MESSY_CODE.matcher(strName);
String after = m.replaceAll("");
String temp = after.replaceAll("\\p{P}", "");
char[] ch = temp.trim().toCharArray();
float chLength = 0;
float count = 0;
for (char c : ch){
if (!Character.isLetterOrDigit(c)) {
if (!isChinese(c)) {
count = count + 1;
}
chLength++;
}
}
return count / chLength;
}
/**
* 18位标准身份证号
* 方法用途:15位身份证转化为18位标准证件号
*/
public static String transIdCard15to18(String IdCardNO){
String cardNo=null;
if(null!=IdCardNO&&IdCardNO.trim().length()==15){
IdCardNO=IdCardNO.trim();
StringBuilder sb=new StringBuilder(IdCardNO);
sb.insert(6, "19");
sb.append(transCardLastNo(sb.toString()));
cardNo=sb.toString();
}
return cardNo;
}
/**
* 15位补全身份证号码
* @param newCardId
* @return
*/
private static String transCardLastNo(String newCardId){
char[] ch=newCardId.toCharArray();
int m=0;
int [] co={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
char [] verCode=new char[]{'1','0','X','9','8','7','6','5','4','3','2'};
for (int i = 0; i < newCardId.length(); i++) {
m+=(ch[i]-'0')*co[i];
}
int residue=m%11;
return String.valueOf(verCode[residue]);
}
}
五、FileUtil.class
package com.supcon.mare.tankinfo.util;
import java.io.*;
import java.math.BigInteger;
import java.net.FileNameMap;
import java.net.URLConnection;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public final class FileUtil {
/**
* Buffer的大小
*/
private static Integer BUFFER_SIZE = 1024 * 1024 * 10;
public static MessageDigest MD5 = null;
static {
try {
MD5 = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException ne) {
ne.printStackTrace();
}
}
/**
* 获取文件的md5
*
* @param file
* @return
*/
public static String fileMD5(File file) {
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(file);
byte[] buffer = new byte[8192];
int length;
while ((length = fileInputStream.read(buffer)) != -1) {
MD5.update(buffer, 0, length);
}
return new BigInteger(1, MD5.digest()).toString(16);
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
try {
if (fileInputStream != null) {
fileInputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 获取文件的行数
*
* @param file 统计的文件
* @return 文件行数
*/
public final static int countLines(File file) {
try (LineNumberReader rf = new LineNumberReader(new FileReader(file))) {
long fileLength = file.length();
rf.skip(fileLength);
return rf.getLineNumber();
} catch (IOException e) {
e.printStackTrace();
}
return 0;
}
/**
* 以列表的方式获取文件的所有行
*
* @param file 需要出来的文件
* @return 包含所有行的list
*/
public final static List<String> lines(File file) {
List<String> list = new ArrayList<>();
try (
BufferedReader reader = new BufferedReader(new FileReader(file))
) {
String line;
while ((line = reader.readLine()) != null) {
list.add(line);
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
/**
* 以列表的方式获取文件的所有行
*
* @param file 需要处理的文件
* @param encoding 指定读取文件的编码
* @return 包含所有行的list
*/
public final static List<String> lines(File file, String encoding) {
List<String> list = new ArrayList<>();
try (
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding))
) {
String line;
while ((line = reader.readLine()) != null) {
list.add(line);
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
/**
* 以列表的方式获取文件的指定的行数数据
*
* @param file 处理的文件
* @param lines 需要读取的行数
* @return 包含制定行的list
*/
public final static List<String> lines(File file, int lines) {
List<String> list = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
while ((line = reader.readLine()) != null) {
list.add(line);
if (list.size() == lines) {
break;
}
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
/**
* 以列表的方式获取文件的指定的行数数据
*
* @param file 需要处理的函数
* @param lines 需要处理的行还俗
* @param encoding 指定读取文件的编码
* @return 包含制定行的list
*/
public final static List<String> lines(File file, int lines, String encoding) {
List<String> list = new ArrayList<>();
try (
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding))
) {
String line;
while ((line = reader.readLine()) != null) {
list.add(line);
if (list.size() == lines) {
break;
}
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
/**
* 在文件末尾追加一行
*
* @param file 需要处理的文件
* @param str 添加的字符串
* @param encoding 指定写入的编码
* @return 是否成功
*/
public final static boolean appendLine(File file, String str, String encoding) {
String lineSeparator = System.getProperty("line.separator", "\n");
try (
RandomAccessFile randomFile = new RandomAccessFile(file, "rw")
) {
long fileLength = randomFile.length();
randomFile.seek(fileLength);
randomFile.write((lineSeparator + str).getBytes(encoding));
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
/**
* 将字符串写入到文件中
*/
public final static boolean write(File file, String str) {
try (
RandomAccessFile randomFile = new RandomAccessFile(file, "rw")
) {
randomFile.writeBytes(str);
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
/**
* 将字符串以追加的方式写入到文件中
*/
public final static boolean writeAppend(File file, String str) {
try (
RandomAccessFile randomFile = new RandomAccessFile(file, "rw")
) {
long fileLength = randomFile.length();
randomFile.seek(fileLength);
randomFile.writeBytes(str);
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
/**
* 将字符串以制定的编码写入到文件中
*/
public final static boolean write(File file, String str, String encoding) {
try (
RandomAccessFile randomFile = new RandomAccessFile(file, "rw")
) {
randomFile.write(str.getBytes(encoding));
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
/**
* 将字符串以追加的方式以制定的编码写入到文件中
*/
public final static boolean writeAppend(File file, String str, String encoding) {
try (
RandomAccessFile randomFile = new RandomAccessFile(file, "rw")
) {
long fileLength = randomFile.length();
randomFile.seek(fileLength);
randomFile.write(str.getBytes(encoding));
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
/**
* 快速清空一个超大的文件
*
* @param file 需要处理的文件
* @return 是否成功
*/
public final static boolean cleanFile(File file) {
try (
FileWriter fw = new FileWriter(file)
) {
fw.write("");
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
/**
* 获取文件的Mime类型
*
* @param file 需要处理的文件
* @return 返回文件的mime类型
* @throws java.io.IOException
*/
public final static String mimeType(String file) throws java.io.IOException {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
return fileNameMap.getContentTypeFor(file);
}
/**
* 获取文件最后的修改时间
*
* @param file 需要处理的文件
* @return 返回文件的修改时间
*/
public final static Date modifyTime(File file) {
return new Date(file.lastModified());
}
/**
* 复制文件
*
* @param resourcePath 源文件
* @param targetPath 目标文件
* @return 是否成功
*/
public final static boolean copy(String resourcePath, String targetPath) {
File file = new File(resourcePath);
return copy(file, targetPath);
}
/**
* 复制文件
* 通过该方式复制文件文件越大速度越是明显
*
* @param file 需要处理的文件
* @param targetFile 目标文件
* @return 是否成功
*/
public final static boolean copy(File file, String targetFile) {
try (
FileInputStream fin = new FileInputStream(file);
FileOutputStream fout = new FileOutputStream(new File(targetFile))
) {
FileChannel in = fin.getChannel();
FileChannel out = fout.getChannel();
//设定缓冲区
ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
while (in.read(buffer) != -1) {
//准备写入,防止其他读取,锁住文件
buffer.flip();
out.write(buffer);
//准备读取。将缓冲区清理完毕,移动文件内部指针
buffer.clear();
}
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
/**
* 创建多级目录
*
* @param paths 需要创建的目录
* @return 是否成功
*/
public final static boolean createPaths(String paths) {
File dir = new File(paths);
return !dir.exists() && dir.mkdir();
}
/**
* 创建文件支持多级目录
*
* @param filePath 需要创建的文件
* @return 是否成功
*/
public final static boolean createFiles(String filePath) {
File file = new File(filePath);
if (file.isDirectory()) {
if (!file.exists()) {
return file.mkdirs();
}
} else {
File dir = file.getParentFile();
if (!dir.exists()) {
if (dir.mkdirs()) {
try {
return file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
return false;
}
/**
* 删除一个文件
*
* @param file 需要处理的文件
* @return 是否成功
*/
public final static boolean deleteFile(File file) {
return file.delete();
}
/**
* 删除一个目录
*
* @param file 需要处理的文件
* @return 是否成功
*/
public final static boolean deleteDir(File file) {
List<File> files = listFileAll(file);
for (File f : files) {
if (f.isDirectory()) {
deleteDir(f);
} else {
deleteFile(f);
}
}
return file.delete();
}
/**
* 快速的删除超大的文件
*
* @param file 需要处理的文件
* @return 是否成功
*/
public final static boolean deleteBigFile(File file) {
return cleanFile(file) && file.delete();
}
/**
* 复制目录
*
* @param filePath 需要处理的文件
* @param targetPath 目标文件
*/
public final static void copyDir(String filePath, String targetPath) {
File file = new File(filePath);
copyDir(file, targetPath);
}
/**
* 复制目录
*
* @param filePath 需要处理的文件
* @param targetPath 目标文件
*/
public final static void copyDir(File filePath, String targetPath) {
File targetFile = new File(targetPath);
if (!targetFile.exists()) {
createPaths(targetPath);
}
File[] files = filePath.listFiles();
for (File file : files) {
String path = file.getName();
if (file.isDirectory()) {
copyDir(file, targetPath + "/" + path);
} else {
copy(file, targetPath + "/" + path);
}
}
}
/**
* 罗列指定路径下的全部文件
*
* @param path 需要处理的文件
* @return 包含所有文件的的list
*/
public final static List<File> listFile(String path) {
File file = new File(path);
return listFile(file);
}
/**
* 罗列指定路径下的全部文件
*
* @param path 需要处理的文件
* @param child 是否罗列子文件
* @return 包含所有文件的的list
*/
public final static List<File> listFile(String path, boolean child) {
return listFile(new File(path), child);
}
/**
* 罗列指定路径下的全部文件
*
* @param path 需要处理的文件
* @return 返回文件列表
*/
public final static List<File> listFile(File path) {
List<File> list = new ArrayList<>();
File[] files = path.listFiles();
for (File file : files) {
if (file.isDirectory()) {
list.addAll(listFile(file));
} else {
list.add(file);
}
}
return list;
}
/**
* 罗列指定路径下的全部文件
*
* @param path 指定的路径
* @param child 是否罗列子目录
* @return
*/
public final static List<File> listFile(File path, boolean child) {
List<File> list = new ArrayList<>();
File[] files = path.listFiles();
for (File file : files) {
if (child && file.isDirectory()) {
list.addAll(listFile(file));
} else {
list.add(file);
}
}
return list;
}
/**
* 罗列指定路径下的全部文件包括文件夹
*
* @param path 需要处理的文件
* @return 返回文件列表
*/
public final static List<File> listFileAll(File path) {
List<File> list = new ArrayList<>();
File[] files = path.listFiles();
for (File file : files) {
list.add(file);
if (file.isDirectory()) {
list.addAll(listFileAll(file));
}
}
return list;
}
/**
* 罗列指定路径下的全部文件包括文件夹
*
* @param path 需要处理的文件
* @param filter 处理文件的filter
* @return 返回文件列表
*/
public final static List<File> listFileFilter(File path, FilenameFilter filter) {
List<File> list = new ArrayList<>();
File[] files = path.listFiles();
for (File file : files) {
if (file.isDirectory()) {
list.addAll(listFileFilter(file, filter));
} else {
if (filter.accept(file.getParentFile(), file.getName())) {
list.add(file);
}
}
}
return list;
}
/**
* 获取指定目录下的特点文件,通过后缀名过滤
*
* @param dirPath 需要处理的文件
* @param postfixs 文件后缀
* @return 返回文件列表
*/
public final static List<File> listFileFilter(File dirPath, final String postfixs) {
/*
如果在当前目录中使用Filter讲只罗列当前目录下的文件不会罗列孙子目录下的文件
FilenameFilter filefilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(postfixs);
}
};
*/
List<File> list = new ArrayList<File>();
File[] files = dirPath.listFiles();
for (File file : files) {
if (file.isDirectory()) {
list.addAll(listFileFilter(file, postfixs));
} else {
String fileName = file.getName().toLowerCase();
if (fileName.endsWith(postfixs.toLowerCase())) {
list.add(file);
}
}
}
return list;
}
/**
* 在指定的目录下搜寻文个文件
*
* @param dirPath 搜索的目录
* @param fileName 搜索的文件名
* @return 返回文件列表
*/
public final static List<File> searchFile(File dirPath, String fileName) {
List<File> list = new ArrayList<>();
File[] files = dirPath.listFiles();
for (File file : files) {
if (file.isDirectory()) {
list.addAll(searchFile(file, fileName));
} else {
String Name = file.getName();
if (Name.equals(fileName)) {
list.add(file);
}
}
}
return list;
}
/**
* 获取文件后缀名
*
* @param file
* @return
*/
public final static String suffix(File file) {
String fileName = file.getName();
return fileName.substring(fileName.indexOf(".") + 1);
}
}
六、ZipUtil.Class
package com.supcon.supfusion.oms.commons.util;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
/**
* 压缩文档相关的工具类
* 注意因为jre中自带的java.util.zip.*包不支持中文及加密压缩,如果需要选择使用zip4j包
*
* @author zhaoxu
*/
public final class ZipUtil {
/**
* zip文件结尾
*/
final static String ZIP_STR = ".zip";
/**
* 判断文件是否为一个压缩文件
*
* @param filePath
* @return
*/
public static boolean isZipFile(String filePath) {
if (!filePath.contains(ZIP_STR)) {
return false;
}
try (ZipFile zipFile = new ZipFile(filePath)) {
} catch (IOException e) {
return false;
}
return true;
}
/**
* 读取压缩文件中的所有文件名
*
* @param path
* @return
* @throws IOException
*/
public static List<String> getZipFileNames(String path) throws IOException {
List<String> fileNamesList = new ArrayList<>();
ZipEntry zipEntry;
File file = new File(path);
//判断文件是否存在
if (file.exists()) {
//解决包内文件存在中文时的中文乱码问题
ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(Paths.get(path)), Charset.forName("GBK"));
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
//遇到文件夹就跳过
if (!zipEntry.isDirectory()) {
fileNamesList.add(zipEntry.getName().substring(zipEntry.getName().lastIndexOf("\\") + 1));
}
}
}
return fileNamesList;
}
/**
* 文档压缩
*
* @param file 需要压缩的文件或目录
* @param dest 压缩后的文件名称
* @throws IOException
*/
public static void deCompress(File file, String dest) throws IOException {
ZipFile zf = new ZipFile(dest);
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(dest))) {
String dir = "";
if (file.isDirectory()) {
dir = file.getName();
}
zipFile(file, zos, dir);
} catch (IOException e) {
throw e;
}
}
public static void zipFile(File inFile, ZipOutputStream zos, String dir) throws IOException {
if (inFile.isDirectory()) {
File[] files = inFile.listFiles();
if (files == null || files.length == 0) {
String entryName = dir + "/";
zos.putNextEntry(new ZipEntry(entryName));
return;
}
for (File file : files) {
String entryName = dir + "/" + file.getName();
if (file.isDirectory()) {
zipFile(file, zos, entryName);
} else {
ZipEntry entry = new ZipEntry(entryName);
zos.putNextEntry(entry);
try (InputStream is = new FileInputStream(file)) {
int len = 0;
while ((len = is.read()) != -1) {
zos.write(len);
}
} catch (IOException e) {
throw e;
}
}
}
} else {
String entryName = dir + "/" + inFile.getName();
ZipEntry entry = new ZipEntry(entryName);
zos.putNextEntry(entry);
try (InputStream is = new FileInputStream(inFile)) {
int len = 0;
while ((len = is.read()) != -1) {
zos.write(len);
}
} catch (IOException e) {
throw e;
}
}
}
/**
* 文档解压
*
* @param source 需要解压缩的文档名称
* @param path 需要解压缩的路径
*/
public static void unCompress(File source, String path) throws IOException {
ZipEntry zipEntry = null;
FileUtil.createPaths(path);
//实例化ZipFile,每一个zip压缩文件都可以表示为一个ZipFile
//实例化一个Zip压缩文件的ZipInputStream对象,可以利用该类的getNextEntry()方法依次拿到每一个ZipEntry对象
try (
ZipFile zipFile = new ZipFile(source);
ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(source))
) {
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
String fileName = zipEntry.getName();
String filePath = path + "/" + fileName;
if (zipEntry.isDirectory()) {
File temp = new File(filePath);
if (!temp.exists()) {
temp.mkdirs();
}
} else {
File temp = new File(filePath);
if (!temp.getParentFile().exists()) {
temp.getParentFile().mkdirs();
}
try (OutputStream os = new FileOutputStream(temp);
//通过ZipFile的getInputStream方法拿到具体的ZipEntry的输入流
InputStream is = zipFile.getInputStream(zipEntry)) {
int len = 0;
while ((len = is.read()) != -1) {
os.write(len);
}
} catch (IOException e) {
throw e;
}
}
}
} catch (IOException e) {
throw e;
}
}
}
七、StringUtil.Class
package com.supcon.mare.tankinfo.util;
import com.alibaba.druid.util.StringUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author ZhaoXu
* @date 2021/11/12 13:20
*/
public class StringUtil {
static Pattern numberPattern = Pattern.compile("[0-9]*");
/**
* time时间戳转Date
*
* @param time
* @return
*/
public static Date timeToDate(String time) {
SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str = sdfTime.format(Long.valueOf(time));
try {
Date date = sdfTime.parse(str);
return date;
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
/**
* 日期字符串转String型Time
*
* @param date
* @return
*/
public static String stringToTime(String date) {
SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date dateDate = sdfTime.parse(date);
return String.valueOf(dateDate.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
/**
* 利用正则表达式判断字符串是否是数字
*
* @param str
* @return
*/
public static boolean isNumeric(String str) {
Matcher isNum = numberPattern.matcher(str);
if (StringUtils.isEmpty(str) || !isNum.matches()) {
return false;
}
return true;
}
/**
* 首字母变小写
* @param str
* @return
*/
public static String firstCharToLowerCase(String str) {
char firstChar = str.charAt(0);
if (firstChar >= 'A' && firstChar <= 'Z') {
char[] arr = str.toCharArray();
arr[0] += ('a' - 'A');
return new String(arr);
}
return str;
}
/**
* 首字母变大写
* @param str
* @return
*/
public static String firstCharToUpperCase(String str) {
char firstChar = str.charAt(0);
if (firstChar >= 'a' && firstChar <= 'z') {
char[] arr = str.toCharArray();
arr[0] -= ('a' - 'A');
return new String(arr);
}
return str;
}
/**
* 判断是否为空
* @param str
* @return
*/
public static boolean isEmpty(final String str) {
return (str == null) || (str.length() == 0);
}
}
八、ImageUtil.class
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* @author ZhaoXu
* @date 2021/11/25 15:21
*/
public class ImageUtil {
public static BufferedImage grayImage(BufferedImage bufferedImage) throws Exception {
int width = bufferedImage.getWidth();
int height = bufferedImage.getHeight();
BufferedImage grayBufferedImage = new BufferedImage(width, height, bufferedImage.getType());
for (int i = 0; i < bufferedImage.getWidth(); i++) {
for (int j = 0; j < bufferedImage.getHeight(); j++) {
final int color = bufferedImage.getRGB(i, j);
final int r = (color >> 16) & 0xff;
final int g = (color >> 8) & 0xff;
final int b = color & 0xff;
int gray = (int) (0.3 * r + 0.59 * g + 0.11 * b);
int newPixel = colorToRGB(255, gray, gray, gray);
grayBufferedImage.setRGB(i, j, newPixel);
}
}
return grayBufferedImage;
}
/**
* 颜色分量转换为RGB值
*
* @param alpha
* @param red
* @param green
* @param blue
* @return
*/
private static int colorToRGB(int alpha, int red, int green, int blue) {
int newPixel = 0;
newPixel += alpha;
newPixel = newPixel << 8;
newPixel += red;
newPixel = newPixel << 8;
newPixel += green;
newPixel = newPixel << 8;
newPixel += blue;
return newPixel;
}
public static BufferedImage binaryImage(BufferedImage image) throws Exception {
int w = image.getWidth();
int h = image.getHeight();
float[] rgb = new float[3];
double[][] zuobiao = new double[w][h];
int black = new Color(0, 0, 0).getRGB();
int white = new Color(255, 255, 255).getRGB();
BufferedImage bi = new BufferedImage(w, h,
BufferedImage.TYPE_BYTE_BINARY);
;
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
int pixel = image.getRGB(x, y);
rgb[0] = (pixel & 0xff0000) >> 16;
rgb[1] = (pixel & 0xff00) >> 8;
rgb[2] = (pixel & 0xff);
float avg = (rgb[0] + rgb[1] + rgb[2]) / 3;
zuobiao[x][y] = avg;
}
}
//这里是阈值,白底黑字还是黑底白字,大多数情况下建议白底黑字,后面都以白底黑字为例
double SW = 192;
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
if (zuobiao[x][y] < SW) {
bi.setRGB(x, y, black);
} else {
bi.setRGB(x, y, white);
}
}
}
return bi;
}
// 自己加周围8个灰度值再除以9,算出其相对灰度值
public static double getGray(double[][] zuobiao, int x, int y, int w, int h) {
double rs = zuobiao[x][y] + (x == 0 ? 255 : zuobiao[x - 1][y]) + (x == 0 || y == 0 ? 255 : zuobiao[x - 1][y - 1])
+ (x == 0 || y == h - 1 ? 255 : zuobiao[x - 1][y + 1]) + (y == 0 ? 255 : zuobiao[x][y - 1])
+ (y == h - 1 ? 255 : zuobiao[x][y + 1]) + (x == w - 1 ? 255 : zuobiao[x + 1][y])
+ (x == w - 1 || y == 0 ? 255 : zuobiao[x + 1][y - 1])
+ (x == w - 1 || y == h - 1 ? 255 : zuobiao[x + 1][y + 1]);
return rs / 9;
}
/**
* 降噪,以1个像素点为单位(实际使用中可以循环降噪,或者把单位可以扩大为多个像素点)
*
* @param image
* @return
*/
public static BufferedImage denoise(BufferedImage image) {
int w = image.getWidth();
int h = image.getHeight();
int white = new Color(255, 255, 255).getRGB();
if (isWhite(image.getRGB(1, 0)) && isWhite(image.getRGB(0, 1)) && isWhite(image.getRGB(1, 1))) {
image.setRGB(0, 0, white);
}
if (isWhite(image.getRGB(w - 2, 0)) && isWhite(image.getRGB(w - 1, 1)) && isWhite(image.getRGB(w - 2, 1))) {
image.setRGB(w - 1, 0, white);
}
if (isWhite(image.getRGB(0, h - 2)) && isWhite(image.getRGB(1, h - 1)) && isWhite(image.getRGB(1, h - 2))) {
image.setRGB(0, h - 1, white);
}
if (isWhite(image.getRGB(w - 2, h - 1)) && isWhite(image.getRGB(w - 1, h - 2)) && isWhite(image.getRGB(w - 2, h - 2))) {
image.setRGB(w - 1, h - 1, white);
}
for (int x = 1; x < w - 1; x++) {
int y = 0;
if (isBlack(image.getRGB(x, y))) {
int size = 0;
if (isWhite(image.getRGB(x - 1, y))) {
size++;
}
if (isWhite(image.getRGB(x + 1, y))) {
size++;
}
if (isWhite(image.getRGB(x, y + 1))) {
size++;
}
if (isWhite(image.getRGB(x - 1, y + 1))) {
size++;
}
if (isWhite(image.getRGB(x + 1, y + 1))) {
size++;
}
if (size >= 5) {
image.setRGB(x, y, white);
}
}
}
for (int x = 1; x < w - 1; x++) {
int y = h - 1;
if (isBlack(image.getRGB(x, y))) {
int size = 0;
if (isWhite(image.getRGB(x - 1, y))) {
size++;
}
if (isWhite(image.getRGB(x + 1, y))) {
size++;
}
if (isWhite(image.getRGB(x, y - 1))) {
size++;
}
if (isWhite(image.getRGB(x + 1, y - 1))) {
size++;
}
if (isWhite(image.getRGB(x - 1, y - 1))) {
size++;
}
if (size >= 5) {
image.setRGB(x, y, white);
}
}
}
for (int y = 1; y < h - 1; y++) {
int x = 0;
if (isBlack(image.getRGB(x, y))) {
int size = 0;
if (isWhite(image.getRGB(x + 1, y))) {
size++;
}
if (isWhite(image.getRGB(x, y + 1))) {
size++;
}
if (isWhite(image.getRGB(x, y - 1))) {
size++;
}
if (isWhite(image.getRGB(x + 1, y - 1))) {
size++;
}
if (isWhite(image.getRGB(x + 1, y + 1))) {
size++;
}
if (size >= 5) {
image.setRGB(x, y, white);
}
}
}
for (int y = 1; y < h - 1; y++) {
int x = w - 1;
if (isBlack(image.getRGB(x, y))) {
int size = 0;
if (isWhite(image.getRGB(x - 1, y))) {
size++;
}
if (isWhite(image.getRGB(x, y + 1))) {
size++;
}
if (isWhite(image.getRGB(x, y - 1))) {
size++;
}
//斜上下为空时,去掉此点
if (isWhite(image.getRGB(x - 1, y + 1))) {
size++;
}
if (isWhite(image.getRGB(x - 1, y - 1))) {
size++;
}
if (size >= 5) {
image.setRGB(x, y, white);
}
}
}
//降噪,以1个像素点为单位
for (int y = 1; y < h - 1; y++) {
for (int x = 1; x < w - 1; x++) {
if (isBlack(image.getRGB(x, y))) {
int size = 0;
//上下左右均为空时,去掉此点
if (isWhite(image.getRGB(x - 1, y))) {
size++;
}
if (isWhite(image.getRGB(x + 1, y))) {
size++;
}
//上下均为空时,去掉此点
if (isWhite(image.getRGB(x, y + 1))) {
size++;
}
if (isWhite(image.getRGB(x, y - 1))) {
size++;
}
//斜上下为空时,去掉此点
if (isWhite(image.getRGB(x - 1, y + 1))) {
size++;
}
if (isWhite(image.getRGB(x + 1, y - 1))) {
size++;
}
if (isWhite(image.getRGB(x + 1, y + 1))) {
size++;
}
if (isWhite(image.getRGB(x - 1, y - 1))) {
size++;
}
if (size >= 8) {
image.setRGB(x, y, white);
}
}
}
}
return image;
}
public static boolean isBlack(int colorInt) {
Color color = new Color(colorInt);
if (color.getRed() + color.getGreen() + color.getBlue() <= 300) {
return true;
}
return false;
}
public static boolean isWhite(int colorInt) {
Color color = new Color(colorInt);
if (color.getRed() + color.getGreen() + color.getBlue() > 300) {
return true;
}
return false;
}
public static int isBlack(int colorInt, int whiteThreshold) {
final Color color = new Color(colorInt);
if (color.getRed() + color.getGreen() + color.getBlue() <= whiteThreshold) {
return 1;
}
return 0;
}
/**
* 放大缩小处理
* @param imgsrc
* @param widthdist
* @param heightdist
*/
public static void reduceImg(String imgsrc, int widthdist, int heightdist) {
try {
File srcfile = new File(imgsrc);
if (!srcfile.exists()) {
return;
}
//载入图片文件
Image src = javax.imageio.ImageIO.read(srcfile);
int w0 = src.getWidth(null); //得到源图宽
int h0 = src.getHeight(null); //得到源图长
BufferedImage tag = new BufferedImage((int) widthdist, (int) heightdist, BufferedImage.TYPE_INT_RGB);
//保存文件
//绘制缩小后的图
tag.getGraphics().drawImage(src.getScaledInstance(widthdist, heightdist, Image.SCALE_SMOOTH), 0, 0, null);
//tag.getGraphics().drawImage(src.getScaledInstance(widthdist, heightdist, Image.SCALE_AREA_AVERAGING), 0, 0, null);
//标注水印
//int x = widthdist/10*8; //水印位置(x,y)
//int y = heightdist/10*8;
//jpg_logo( tag , x , y );
//重命名并新建图片
String oleName = imgsrc.substring(imgsrc.indexOf(".") - 1, imgsrc.indexOf("."));
String newName = oleName + "v";
String imgdist = imgsrc.replace(oleName, newName);
//输出到文件流
FileOutputStream out = new FileOutputStream(imgsrc);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
//近JPEG编码
encoder.encode(tag);
out.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
九、类转换工具
package com.gpt.wechat.util;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.util.CollectionUtils;
import java.io.Serializable;
import java.util.*;
/**
* @author: zhaoxu
*/
public class BaseConverter {
private static final Logger log = LoggerFactory.getLogger(BaseConverter.class);
Mapper beanMapper = new DozerBeanMapper();
public BaseConverter() {
}
public <S, D> D convertSingleObject(S source, Class<D> clazz) {
if (source == null) {
return null;
} else {
D dest = null;
try {
dest = beanMapper.map(source, clazz);
} catch (Exception e) {
log.error("初始化{}对象失败。", clazz, e);
}
return dest;
}
}
public <S, D> List<D> convertMultiObjectToList(List<S> sourceList, Class<D> destClass) {
if (CollectionUtils.isEmpty(sourceList)) {
return null;
} else {
List<D> toList = new ArrayList<>();
for (S src : sourceList) {
toList.add(this.convertSingleObject(src, destClass));
}
return toList;
}
}
public <S, D> PageResponse<D> convertMultiObjectToPage(Page<S> srcPages, Class<D> destClass) {
PageResponse<D> pageResponse = new PageResponse<>();
List<D> destList = new ArrayList<>();
if (srcPages != null && srcPages.getContent() != null) {
for (S srcPage : srcPages) {
destList.add(this.convertSingleObject(srcPage, destClass));
}
}
pageResponse.setTotal(srcPages.getTotalElements());
pageResponse.setData(destList);
pageResponse.setPageSize(srcPages.getSize());
pageResponse.setCurrent(srcPages.getNumber() + 1);
return pageResponse;
}
@Data
@NoArgsConstructor
public static class PageResponse<S> implements Serializable {
private static final long serialVersionUID = -3355752076145642645L;
/**
* 总数
*/
Long total;
/**
* 当前页
*/
Integer current;
/**
* 每页条数
*/
Integer pageSize;
/**
* 数据
*/
List<S> data;
}
}