mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-20 18:56:01 +08:00
优化数组支持
This commit is contained in:
@@ -58,7 +58,8 @@ public class FastBeanCopier {
|
||||
}
|
||||
|
||||
public static void copy(Object source, Object target, Converter converter, String... ignore) {
|
||||
getCopier(source, target, true).copy(source, target, (ignore == null || ignore.length == 0) ? new HashSet<>() : new HashSet<>(Arrays.asList(ignore)), converter);
|
||||
getCopier(source, target, true)
|
||||
.copy(source, target, (ignore == null || ignore.length == 0) ? new HashSet<>() : new HashSet<>(Arrays.asList(ignore)), converter);
|
||||
}
|
||||
|
||||
private static String createCacheKey(Class source, Class target) {
|
||||
@@ -162,8 +163,12 @@ public class FastBeanCopier {
|
||||
.append(source.getReadMethod().getName())
|
||||
.append("()!=null");
|
||||
}
|
||||
String targetTypeName = target.getPropertyType().getName();
|
||||
if (target.getPropertyType().isArray()) {
|
||||
targetTypeName = target.getPropertyType().getComponentType().getName() + "[]";
|
||||
}
|
||||
convertCode.append("){\n");
|
||||
convertCode.append(target.getPropertyType().getName())
|
||||
convertCode.append(targetTypeName)
|
||||
.append(" ")
|
||||
.append(target.getName()).append("=");
|
||||
String convert = "converter.convert((Object)(" + getReadSourceObjectValueCode() + "),"
|
||||
|
||||
@@ -23,6 +23,7 @@ public class FastBeanCopierTest {
|
||||
Source source = new Source();
|
||||
source.setAge(100);
|
||||
source.setName("测试");
|
||||
source.setIds(new String[]{"1","2","3"});
|
||||
NestObject nestObject = new NestObject();
|
||||
nestObject.setAge(10);
|
||||
nestObject.setName("测试2");
|
||||
|
||||
@@ -11,4 +11,5 @@ public class NestObject {
|
||||
private String name;
|
||||
|
||||
private int age;
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import lombok.Data;
|
||||
public class Source {
|
||||
private String name;
|
||||
private int age;
|
||||
private String[] ids;
|
||||
|
||||
private NestObject nestObject;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import lombok.Data;
|
||||
public class Target {
|
||||
private String name;
|
||||
private int age;
|
||||
private String[] ids;
|
||||
private NestObject nestObject;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user