Merge branch 'v6-dev' of gitee.com:dromara/hutool into v6-dev

This commit is contained in:
Looly 2023-12-05 00:08:59 +08:00
commit 671c4031d7
2 changed files with 9 additions and 11 deletions

View File

@ -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> 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> 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> 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();
}
/**

View File

@ -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);
}