|
|
@@ -2,13 +2,11 @@ package com.github.jfcloud.gene.handler;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import freemarker.template.SimpleScalar;
|
|
|
import freemarker.template.TemplateMethodModelEx;
|
|
|
import freemarker.template.TemplateModelException;
|
|
|
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* freemarker自定义函数:json过滤器
|
|
|
@@ -21,18 +19,28 @@ public class MyJsonFilter implements TemplateMethodModelEx {
|
|
|
}
|
|
|
//第一个参数为json字符串
|
|
|
Object value = arguments.get(0);
|
|
|
+ //转为string字符串
|
|
|
+ if (value instanceof SimpleScalar) {
|
|
|
+ value = value.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> params = new ArrayList<>();
|
|
|
+ for (Object argument : arguments) {
|
|
|
+ params.add(Objects.toString(argument, ""));
|
|
|
+ }
|
|
|
+
|
|
|
//第二个参数为json路径
|
|
|
- String path = arguments.get(1).toString();
|
|
|
- //第三个参数为方法
|
|
|
- String method = arguments.get(2).toString();
|
|
|
+ String path = params.get(1);
|
|
|
+ //第三个参数为方法 eq/ne/contain/comma_contain
|
|
|
+ String method = params.get(2);
|
|
|
//第四个参数为期望值
|
|
|
- String expect = arguments.get(3).toString();
|
|
|
+ String expect = params.get(3);
|
|
|
//第五个参数为结果类型:obj返回对象,wt返回<w:t>标签,check返回勾选框,bool返回布尔值
|
|
|
- String resultType = arguments.get(4).toString();
|
|
|
+ String resultType = params.get(4);
|
|
|
|
|
|
//根据json路径获取值
|
|
|
if (StrUtil.isNotBlank(path)) {
|
|
|
- value = JSONUtil.parseObj(String.valueOf(value)).getByPath(path);
|
|
|
+ value = JSONUtil.parseObj(Objects.toString(value, "")).getByPath(path);
|
|
|
}
|
|
|
if ("obj".equals(resultType)) {
|
|
|
return value;
|