添加 string.uuid() 函数

This commit is contained in:
吕金泽 2019-07-25 18:48:06 +08:00
parent cac30106aa
commit 4630fde7a7
4 changed files with 10780 additions and 2 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -12,12 +12,20 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.mxd.spider.core.freemarker.functions.FreemarkerTemplateMethodModel; import com.mxd.spider.core.freemarker.functions.FreemarkerTemplateMethodModel;
import com.mxd.spider.core.freemarker.functions.utils.*; import com.mxd.spider.core.freemarker.functions.utils.Base64FunctionUtils;
import com.mxd.spider.core.freemarker.functions.utils.DateFunctionUtils;
import com.mxd.spider.core.freemarker.functions.utils.FileFunctionUtils;
import com.mxd.spider.core.freemarker.functions.utils.ListFunctionUtils;
import com.mxd.spider.core.freemarker.functions.utils.RandomFunctionUtils;
import com.mxd.spider.core.freemarker.functions.utils.StringFunctionUtils;
import com.mxd.spider.core.freemarker.functions.utils.UrlFunctionUtils;
import com.mxd.spider.core.utils.ExtractUtils; import com.mxd.spider.core.utils.ExtractUtils;
import freemarker.ext.beans.BeansWrapper; import freemarker.ext.beans.BeansWrapper;
import freemarker.ext.beans.BeansWrapperBuilder; import freemarker.ext.beans.BeansWrapperBuilder;
import freemarker.template.Configuration; import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapperBuilder;
import freemarker.template.ObjectWrapper;
import freemarker.template.Template; import freemarker.template.Template;
import freemarker.template.TemplateHashModel; import freemarker.template.TemplateHashModel;
import freemarker.template.TemplateModelException; import freemarker.template.TemplateModelException;
@ -49,9 +57,10 @@ public class FreeMarkerEngine {
*/ */
private void loadStaticFunctions() throws TemplateModelException{ private void loadStaticFunctions() throws TemplateModelException{
BeansWrapperBuilder builder = new BeansWrapperBuilder(Configuration.VERSION_2_3_28); BeansWrapperBuilder builder = new BeansWrapperBuilder(Configuration.VERSION_2_3_28);
ObjectWrapper wrapper = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_28).build();
builder.setOuterIdentity((obj)->{ builder.setOuterIdentity((obj)->{
threadLocal.set(new FreemarkerObject(obj)); threadLocal.set(new FreemarkerObject(obj));
return null; return wrapper.wrap(obj);
}); });
BeansWrapper beansWrapper = builder.build(); BeansWrapper beansWrapper = builder.build();
TemplateHashModel model = beansWrapper.getStaticModels(); TemplateHashModel model = beansWrapper.getStaticModels();

View File

@ -4,6 +4,7 @@ import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID;
public class StringFunctionUtils { public class StringFunctionUtils {
@ -78,4 +79,17 @@ public class StringFunctionUtils {
return null; return null;
} }
} }
public static String uuid() {
return UUID.randomUUID().toString().replace("-", "");
}
public static List<String> uuids(Integer size) {
List<String> ids = new ArrayList<String>();
for (int i = 0; i < size; i++) {
ids.add(UUID.randomUUID().toString().replace("-", ""));
}
return ids;
}
} }