update 小改

master
管理员 1 year ago
parent b75d2b0f9a
commit 9a0968f87c

@ -503,8 +503,9 @@ public class MongoUtil {
* @param entity * @param entity
* @param <T> * @param <T>
*/ */
public static <T> void fillId(T entity) { public static <T> T fillId(T entity) {
fillId(entity, FillIdType.auto); fillId(entity, FillIdType.auto);
return entity;
} }
@ -515,12 +516,12 @@ public class MongoUtil {
* @param type * @param type
* @param <T> * @param <T>
*/ */
public static <T> void fillId(T entity, FillIdType type) { public static <T> T fillId(T entity, FillIdType type) {
Assert.notNull(entity, "entity不能为空"); Assert.notNull(entity, "entity不能为空");
Field[] fs = ReflectUtil.getFields(entity.getClass(), field -> field.isAnnotationPresent(Id.class)); Field[] fs = ReflectUtil.getFields(entity.getClass(), field -> field.isAnnotationPresent(Id.class));
if (fs.length != 1) { if (fs.length != 1) {
return; return entity;
} }
Field f = fs[0]; Field f = fs[0];
if (f.getType() == Integer.class) { if (f.getType() == Integer.class) {
@ -544,7 +545,7 @@ public class MongoUtil {
ReflectUtil.setFieldValue(entity, f, UUID.fastUUID().toString(true)); ReflectUtil.setFieldValue(entity, f, UUID.fastUUID().toString(true));
} }
} }
return entity;
} }

Loading…
Cancel
Save