feat(自定义对比): 功能开发
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.jero.common.util;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BeanCopyUtils {
|
||||
private BeanCopyUtils() {
|
||||
}
|
||||
|
||||
/** 1、单个对象*/
|
||||
public static <V> V copyBean(Object source, Class<V> clazz) {
|
||||
/** 创建目标对象 实现属性拷贝*/
|
||||
V result = null;
|
||||
try {
|
||||
result = clazz.newInstance();
|
||||
/** 拷贝*/
|
||||
BeanUtils.copyProperties(source, result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 2、集合*/
|
||||
public static <O, V> List<V> copyBeanList(List<O> list, Class<V> clazz) {
|
||||
/** 创建目标对象 实现属性拷贝*/
|
||||
return list.stream()
|
||||
.map(o -> copyBean(o, clazz))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.jero.common.util;
|
||||
|
||||
import cn.hutool.core.lang.Snowflake;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
|
||||
public class SnowflakeUtils {
|
||||
|
||||
private SnowflakeUtils(){
|
||||
|
||||
}
|
||||
|
||||
public static long snowflake(){
|
||||
Snowflake snowflake = IdUtil.getSnowflake(1, 1);
|
||||
return snowflake.nextId();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user