diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/bean/BeanUtil.java b/hutool-core/src/main/java/org/dromara/hutool/core/bean/BeanUtil.java index 2c499aa20..e29286152 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/bean/BeanUtil.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/bean/BeanUtil.java @@ -680,8 +680,7 @@ public class BeanUtil { return (T) RecordConverter.INSTANCE.convert(tClass, source); } final T target = ConstructorUtil.newInstanceIfPossible(tClass); - copyProperties(source, target, CopyOptions.of().setIgnoreProperties(ignoreProperties)); - return target; + return copyProperties(source, target, CopyOptions.of().setIgnoreProperties(ignoreProperties)); } /** @@ -692,8 +691,8 @@ public class BeanUtil { * @param target 目标Bean对象 * @param ignoreProperties 不拷贝的的属性列表 */ - public static void copyProperties(final Object source, final Object target, final String... ignoreProperties) { - copyProperties(source, target, CopyOptions.of().setIgnoreProperties(ignoreProperties)); + public static T copyProperties(final Object source, final T target, final String... ignoreProperties) { + return copyProperties(source, target, CopyOptions.of().setIgnoreProperties(ignoreProperties)); } /** @@ -703,8 +702,8 @@ public class BeanUtil { * @param target 目标Bean对象 * @param ignoreCase 是否忽略大小写 */ - public static void copyProperties(final Object source, final Object target, final boolean ignoreCase) { - BeanCopier.of(source, target, CopyOptions.of().setIgnoreCase(ignoreCase)).copy(); + public static T copyProperties(final Object source, final T target, final boolean ignoreCase) { + return BeanCopier.of(source, target, CopyOptions.of().setIgnoreCase(ignoreCase)).copy(); } /** @@ -715,11 +714,11 @@ public class BeanUtil { * @param target 目标Bean对象 * @param copyOptions 拷贝选项,见 {@link CopyOptions} */ - public static void copyProperties(final Object source, final Object target, final CopyOptions copyOptions) { + public static T copyProperties(final Object source, final T target, final CopyOptions copyOptions) { if (null == source || null == target) { - return; + return null; } - BeanCopier.of(source, target, ObjUtil.defaultIfNull(copyOptions, CopyOptions::of)).copy(); + return BeanCopier.of(source, target, ObjUtil.defaultIfNull(copyOptions, CopyOptions::of)).copy(); } /** diff --git a/hutool-db/src/test/java/org/dromara/hutool/db/driver/DriverUtilTest.java b/hutool-db/src/test/java/org/dromara/hutool/db/driver/DriverUtilTest.java index 1d38d567f..296b42835 100644 --- a/hutool-db/src/test/java/org/dromara/hutool/db/driver/DriverUtilTest.java +++ b/hutool-db/src/test/java/org/dromara/hutool/db/driver/DriverUtilTest.java @@ -13,7 +13,6 @@ package org.dromara.hutool.db.driver; import org.dromara.hutool.core.util.RandomUtil; -import org.dromara.hutool.db.driver.DriverUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -25,7 +24,7 @@ public class DriverUtilTest { @Test public void identifyH2DriverTest(){ final String url = "jdbc:h2:file:./db/test;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE;MODE=MYSQL"; - final String driver = DriverUtil.identifyDriver(url); // driver 返回 mysql 的 driver + final String driver = DriverUtil.identifyDriver(url); // driver 返回 h2 的 driver Assertions.assertEquals("org.h2.Driver", driver); }