mirror of
https://gitee.com/dromara/MilvusPlus.git
synced 2025-12-07 17:38:24 +08:00
实体类转换为MilvusEntity对象添加父类属性
This commit is contained in:
parent
8abb87a0ed
commit
519bd52d04
@ -75,9 +75,9 @@ public class MilvusConverter {
|
|||||||
List<IndexParam> indexParams = new ArrayList<>();
|
List<IndexParam> indexParams = new ArrayList<>();
|
||||||
// 用于存储属性与函数映射的缓存
|
// 用于存储属性与函数映射的缓存
|
||||||
PropertyCache propertyCache = new PropertyCache();
|
PropertyCache propertyCache = new PropertyCache();
|
||||||
|
List<Field> fields = getAllFieldsFromClass(entityClass);
|
||||||
// 遍历实体类的所有字段,读取@MilvusField注解信息
|
// 遍历实体类的所有字段,读取@MilvusField注解信息
|
||||||
for (Field field : entityClass.getDeclaredFields()) {
|
for (Field field : fields) {
|
||||||
MilvusField fieldAnnotation = field.getAnnotation(MilvusField.class);
|
MilvusField fieldAnnotation = field.getAnnotation(MilvusField.class);
|
||||||
if (Objects.isNull(fieldAnnotation)) {
|
if (Objects.isNull(fieldAnnotation)) {
|
||||||
continue;
|
continue;
|
||||||
@ -131,7 +131,24 @@ public class MilvusConverter {
|
|||||||
|
|
||||||
return milvus;
|
return milvus;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 递归获取类及其所有父类的所有字段。
|
||||||
|
*
|
||||||
|
* @param clazz 要检查的类。
|
||||||
|
* @return 包含所有字段的列表。
|
||||||
|
*/
|
||||||
|
public static List<Field> getAllFieldsFromClass(Class<?> clazz) {
|
||||||
|
List<Field> fields = new ArrayList<>();
|
||||||
|
// 递归地获取字段直到Object类
|
||||||
|
while (clazz != null && clazz != Object.class) {
|
||||||
|
// 获取当前类的所有字段并添加到列表中
|
||||||
|
fields.addAll(Stream.of(clazz.getDeclaredFields())
|
||||||
|
.peek(field -> field.setAccessible(true)) // 确保可以访问私有字段
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
clazz = clazz.getSuperclass(); // 移动到父类
|
||||||
|
}
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据字段信息和字段名称创建索引参数对象。
|
* 根据字段信息和字段名称创建索引参数对象。
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user