新增ObjectId函数

This commit is contained in:
mxd
2022-08-28 21:37:47 +08:00
parent 7c66d61b59
commit 05940578ee
2 changed files with 40 additions and 0 deletions

View File

@@ -28,4 +28,9 @@ public class MagicMongoConfiguration implements MagicPluginConfiguration {
JavaReflection.registerMethodExtension(FindIterable.class, new MongoFindIterableExtension());
return new MongoModule(mongoTemplate);
}
@Bean
public MongoFunction mongoFunction(){
return new MongoFunction();
}
}

View File

@@ -0,0 +1,35 @@
package org.ssssssss.magicapi.mongo;
import org.bson.types.ObjectId;
import org.ssssssss.magicapi.core.config.MagicFunction;
import org.ssssssss.script.annotation.Comment;
import org.ssssssss.script.annotation.Function;
import java.util.Date;
public class MongoFunction implements MagicFunction {
@Comment("创建ObjectId")
@Function
public ObjectId ObjectId(String hexString){
return new ObjectId(hexString);
}
@Comment("创建ObjectId")
@Function
public ObjectId ObjectId(){
return new ObjectId();
}
@Comment("创建ObjectId")
@Function
public ObjectId ObjectId(byte[] bytes){
return new ObjectId(bytes);
}
@Comment("创建ObjectId")
@Function
public ObjectId ObjectId(Date date){
return new ObjectId(date);
}
}