🐛 Fixing a bug. log insert spel 执行报错. ✨ Introducing new features. support spel 'expression'
This commit is contained in:
1 parent
182c30112e
commit
de66f43616
2 files changed
+15
-2
No files matched your search
+6
@@ -36,4 +36,10 @@ public @interface SysLog {
|
||||
*/
|
||||
String value();
|
||||
|
||||
/**
|
||||
* spel 表达式
|
||||
* @return 日志描述
|
||||
*/
|
||||
String expression() default "";
|
||||
|
||||
}
|
||||
+9
-2
@@ -58,11 +58,18 @@ public class SysLogAspect {
|
||||
log.debug("[类名]:{},[方法]:{}", strClassName, strMethodName);
|
||||
|
||||
String value = sysLog.value();
|
||||
if (StrUtil.isNotBlank(value)) {
|
||||
String expression = sysLog.expression();
|
||||
// 当前表达式存在 SPEL,会覆盖 value 的值
|
||||
if (StrUtil.isNotBlank(expression)) {
|
||||
// 解析SPEL
|
||||
MethodSignature signature = (MethodSignature) point.getSignature();
|
||||
EvaluationContext context = SysLogUtils.getContext(point.getArgs(), signature.getMethod());
|
||||
value = SysLogUtils.getValue(context, value, String.class);
|
||||
try {
|
||||
value = SysLogUtils.getValue(context, expression, String.class);
|
||||
} catch (Exception e) {
|
||||
// SPEL 表达式异常,则获取 value 的值
|
||||
log.error("@SysLog 解析SPEL {} 异常", expression);
|
||||
}
|
||||
}
|
||||
|
||||
SysLogDTO logDTO = SysLogUtils.getSysLog();
|
||||
|
||||
Reference in new issue
Block a user