|
@@ -21,18 +21,22 @@ public class SpElFieldExtractor {
|
|
|
*/
|
|
*/
|
|
|
public Map<String, String> extractFields(Object returnValue, List<SpElMapping> mappings) {
|
|
public Map<String, String> extractFields(Object returnValue, List<SpElMapping> mappings) {
|
|
|
Map<String, String> result = new HashMap<>();
|
|
Map<String, String> result = new HashMap<>();
|
|
|
- EvaluationContext context = new StandardEvaluationContext();
|
|
|
|
|
- context.setVariable("ret", returnValue);
|
|
|
|
|
|
|
+ if (returnValue == null || mappings == null || mappings.isEmpty()) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ EvaluationContext context = new StandardEvaluationContext(returnValue);
|
|
|
|
|
+ context.setVariable("ret", returnValue); // 支持 #ret 方式
|
|
|
|
|
|
|
|
for (SpElMapping mapping : mappings) {
|
|
for (SpElMapping mapping : mappings) {
|
|
|
try {
|
|
try {
|
|
|
- String value = parser.parseExpression(mapping.getSpel())
|
|
|
|
|
- .getValue(context, String.class);
|
|
|
|
|
- result.put(mapping.getFieldName(), value);
|
|
|
|
|
|
|
+ Object val = parser.parseExpression(mapping.getSpel()).getValue(context);
|
|
|
|
|
+ result.put(mapping.getFieldName(), val != null ? val.toString() : null);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
result.put(mapping.getFieldName(), "SpEL解析失败");
|
|
result.put(mapping.getFieldName(), "SpEL解析失败");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|