mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-18 06:27:01 +00:00
fix[orm]: 修复了map的key类型校验错误,mongodb的key只能为string
This commit is contained in:
@@ -511,8 +511,8 @@ public class OrmManager implements IOrmManager {
|
||||
var keyType = types[0];
|
||||
var valueType = types[1];
|
||||
|
||||
if (!isBaseType((Class<?>) keyType)) {
|
||||
throw new RunException("ORM[class:{}]类型声明不正确,Map的key类型必须为基础类型,value必须是普通的pojo", clazz.getCanonicalName());
|
||||
if (!String.class.isAssignableFrom((Class<?>) keyType)) {
|
||||
throw new RunException("ORM[class:{}]类型声明不正确,Map的key类型必须为String类型", clazz.getCanonicalName());
|
||||
}
|
||||
|
||||
checkSubEntity(clazz, valueType);
|
||||
@@ -536,8 +536,7 @@ public class OrmManager implements IOrmManager {
|
||||
checkSubEntity(currentEntityClass, ((ParameterizedType) type).getActualTypeArguments()[0]);
|
||||
return;
|
||||
} else if (Map.class.equals(clazz)) {
|
||||
// Map<List<String>, List<String>>
|
||||
throw new RunException("ORM不支持Map类型");
|
||||
return;
|
||||
}
|
||||
} else if (type instanceof Class) {
|
||||
Class<?> clazz = ((Class<?>) type);
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Ignore
|
||||
public class MapTest {
|
||||
@@ -55,6 +56,10 @@ public class MapTest {
|
||||
bagMap.put("bag2", bagItem2);
|
||||
bagMap.put("bag3", bagItem3);
|
||||
|
||||
var map = new HashMap<String, Map<String, String>>();
|
||||
map.put("a", Map.of("b", "b"));
|
||||
entity.setBaseMap(map);
|
||||
|
||||
OrmContext.getAccessor().insert(entity);
|
||||
|
||||
var myEntity = OrmContext.getAccessor().load(1, MapEntity.class);
|
||||
|
||||
@@ -29,6 +29,8 @@ public class MapEntity implements IEntity<Long> {
|
||||
|
||||
private Map<String, BagItem> bagMap = new HashMap<>();
|
||||
|
||||
private Map<String, Map<String, String>> baseMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Long id() {
|
||||
return id;
|
||||
@@ -50,6 +52,13 @@ public class MapEntity implements IEntity<Long> {
|
||||
this.bagMap = bagMap;
|
||||
}
|
||||
|
||||
public Map<String, Map<String, String>> getBaseMap() {
|
||||
return baseMap;
|
||||
}
|
||||
|
||||
public void setBaseMap(Map<String, Map<String, String>> baseMap) {
|
||||
this.baseMap = baseMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
Reference in New Issue
Block a user