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