mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add copyToList
This commit is contained in:
@@ -3,13 +3,14 @@
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# 5.6.4 (2021-04-19)
|
# 5.6.4 (2021-04-20)
|
||||||
|
|
||||||
### 新特性
|
### 新特性
|
||||||
* 【core 】 DatePattern补充DateTimeFormatter(pr#308@Gitee)
|
* 【core 】 DatePattern补充DateTimeFormatter(pr#308@Gitee)
|
||||||
* 【core 】 DateUtil.compare增加支持给定格式比较(pr#310@Gitee)
|
* 【core 】 DateUtil.compare增加支持给定格式比较(pr#310@Gitee)
|
||||||
* 【core 】 BeanUtil增加edit方法(issue#I3J6BG@Gitee)
|
* 【core 】 BeanUtil增加edit方法(issue#I3J6BG@Gitee)
|
||||||
* 【db 】 Column中加入columnDef字段默认值(issue#I3J6BG@Gitee)
|
* 【db 】 Column中加入columnDef字段默认值(issue#I3J6BG@Gitee)
|
||||||
|
* 【core 】 BeanUtil增加copyToList方法(issue#1526@Github)
|
||||||
|
|
||||||
### Bug修复
|
### Bug修复
|
||||||
* 【db 】 修复SQL分页时未使用别名导致的错误,同时count时取消order by子句(issue#I3IJ8X@Gitee)
|
* 【db 】 修复SQL分页时未使用别名导致的错误,同时count时取消order by子句(issue#I3IJ8X@Gitee)
|
||||||
|
@@ -29,6 +29,7 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bean工具类
|
* Bean工具类
|
||||||
@@ -714,6 +715,25 @@ public class BeanUtil {
|
|||||||
BeanCopier.create(source, target, copyOptions).copy();
|
BeanCopier.create(source, target, copyOptions).copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 复制集合中的Bean属性<br>
|
||||||
|
* 此方法遍历集合中每个Bean,复制其属性后加入一个新的{@link List}中。
|
||||||
|
*
|
||||||
|
* @param collection 原Bean集合
|
||||||
|
* @param targetType 目标Bean类型
|
||||||
|
* @param copyOptions 拷贝选项
|
||||||
|
* @param <T> Bean类型
|
||||||
|
* @return 复制后的List
|
||||||
|
* @since 5.6.4
|
||||||
|
*/
|
||||||
|
public static <T> List<T> copyToList(Collection<?> collection, Class<T> targetType, CopyOptions copyOptions){
|
||||||
|
return collection.stream().map((source)->{
|
||||||
|
final T target = ReflectUtil.newInstanceIfPossible(targetType);
|
||||||
|
copyProperties(source, target, copyOptions);
|
||||||
|
return target;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 给定的Bean的类名是否匹配指定类名字符串<br>
|
* 给定的Bean的类名是否匹配指定类名字符串<br>
|
||||||
* 如果isSimple为{@code false},则只匹配类名而忽略包名,例如:cn.hutool.TestEntity只匹配TestEntity<br>
|
* 如果isSimple为{@code false},则只匹配类名而忽略包名,例如:cn.hutool.TestEntity只匹配TestEntity<br>
|
||||||
@@ -845,4 +865,5 @@ public class BeanUtil {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user