mirror of
				https://gitee.com/dromara/hutool.git
				synced 2025-10-31 16:36:56 +08:00 
			
		
		
		
	add method
This commit is contained in:
		| @@ -3,11 +3,12 @@ | ||||
|  | ||||
| ------------------------------------------------------------------------------------------------------------- | ||||
|  | ||||
| # 5.8.0.M4 (2022-04-14) | ||||
| # 5.8.0.M4 (2022-04-15) | ||||
|  | ||||
| ### ❌不兼容特性 | ||||
|  | ||||
| ### 🐣新特性 | ||||
| * 【core   】     BeanUtil增加toBean重载(pr#598@Gitee) | ||||
|  | ||||
| ### 🐞Bug修复 | ||||
|  | ||||
|   | ||||
| @@ -30,6 +30,7 @@ import java.util.LinkedHashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.function.Consumer; | ||||
| import java.util.function.Supplier; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| /** | ||||
| @@ -548,10 +549,24 @@ public class BeanUtil { | ||||
| 	 * @since 5.2.4 | ||||
| 	 */ | ||||
| 	public static <T> T toBean(Object source, Class<T> clazz, CopyOptions options) { | ||||
| 		if (null == source) { | ||||
| 		return toBean(source, () -> ReflectUtil.newInstanceIfPossible(clazz), options); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * 对象或Map转Bean | ||||
| 	 * | ||||
| 	 * @param <T>            转换的Bean类型 | ||||
| 	 * @param source         Bean对象或Map | ||||
| 	 * @param targetSupplier 目标的Bean创建器 | ||||
| 	 * @param options        属性拷贝选项 | ||||
| 	 * @return Bean对象 | ||||
| 	 * @since 5.8.0 | ||||
| 	 */ | ||||
| 	public static <T> T toBean(Object source, Supplier<T> targetSupplier, CopyOptions options) { | ||||
| 		if (null == source || null == targetSupplier) { | ||||
| 			return null; | ||||
| 		} | ||||
| 		final T target = ReflectUtil.newInstanceIfPossible(clazz); | ||||
| 		final T target = targetSupplier.get(); | ||||
| 		copyProperties(source, target, options); | ||||
| 		return target; | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Looly
					Looly