mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-06 16:48:24 +08:00
!387 FieldWrapper 处理优化,修复entity部分更新时如有字段类型类似Map<String,List<XXX>>报错的问
Merge pull request !387 from tangxin/main
This commit is contained in:
commit
8e72651335
@ -105,7 +105,12 @@ public class FieldWrapper {
|
|||||||
Type genericType = field.getGenericType();
|
Type genericType = field.getGenericType();
|
||||||
if (genericType instanceof ParameterizedType) {
|
if (genericType instanceof ParameterizedType) {
|
||||||
fieldWrapper.keyType = (Class<?>) ((ParameterizedType) genericType).getActualTypeArguments()[0];
|
fieldWrapper.keyType = (Class<?>) ((ParameterizedType) genericType).getActualTypeArguments()[0];
|
||||||
fieldWrapper.mappingType = (Class<?>) ((ParameterizedType) genericType).getActualTypeArguments()[1];
|
Type actualTypeArgument = ((ParameterizedType) genericType).getActualTypeArguments()[1];
|
||||||
|
if (actualTypeArgument instanceof ParameterizedType) {
|
||||||
|
fieldWrapper.mappingType = (Class<?>) ((ParameterizedType) actualTypeArgument).getRawType();
|
||||||
|
} else {
|
||||||
|
fieldWrapper.mappingType = (Class<?>) actualTypeArgument;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fieldWrapper.mappingType = fieldType;
|
fieldWrapper.mappingType = fieldType;
|
||||||
|
|||||||
@ -0,0 +1,63 @@
|
|||||||
|
|
||||||
|
|
||||||
|
package com.mybatisflex.coretest;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.util.FieldWrapper;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tangxin
|
||||||
|
* @since 2023-12-06
|
||||||
|
*/
|
||||||
|
public class FieldWrapperTest {
|
||||||
|
public static class Demo {
|
||||||
|
private Map<String,Object> map1;
|
||||||
|
private Map<String, List<Long>> map2 ;
|
||||||
|
|
||||||
|
public Map<String, Object> getMap1() {
|
||||||
|
return map1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMap1(Map<String, Object> map1) {
|
||||||
|
this.map1 = map1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, List<Long>> getMap2() {
|
||||||
|
return map2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMap2(Map<String, List<Long>> map2) {
|
||||||
|
this.map2 = map2;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void test01() {
|
||||||
|
try {
|
||||||
|
Map<String, List<Long>> listMap = new HashMap<>(0);
|
||||||
|
List<Long> list = new ArrayList<>();
|
||||||
|
list.add(1L);
|
||||||
|
list.add(2L);
|
||||||
|
listMap.put("1", list);
|
||||||
|
Demo demo = new Demo();
|
||||||
|
FieldWrapper fieldWrapper1 = FieldWrapper.of(demo.getClass(), "map1");
|
||||||
|
FieldWrapper fieldWrapper2 = FieldWrapper.of(demo.getClass(), "map2");
|
||||||
|
fieldWrapper1.set(listMap, demo);
|
||||||
|
fieldWrapper2.set(listMap, demo);
|
||||||
|
Map<String, Object> map1 = (Map<String, Object>) fieldWrapper1.get(demo);
|
||||||
|
Map<String, List<Long>> map2 = (Map<String, List<Long>>) fieldWrapper1.get(demo);
|
||||||
|
System.out.println(map1.get("1"));
|
||||||
|
System.out.println(map2.get("1").get(0));
|
||||||
|
}catch (Exception e){
|
||||||
|
assert false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user