Aspectj覆盖方法的参数 [英] Aspectj overwrite an argument of a method
本文介绍了Aspectj覆盖方法的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个方面来检查setter方法的参数并用空值覆盖空字符串。到目前为止这是我的州:
I'm developing an aspect that checks arguments of setter methods and overwrites empty strings with null value. This is my state so far:
@Before("execution(* de.foo.entity.*.set*(..)) && args(java.lang.String)")
public void check(final JoinPoint jp) {
LOGGER.debug(jp.getSignature().toLongString());
Object[] args = jp.getArgs();
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof String && ((String) args[i]).isEmpty()) {
args[i] = null;
}
}
}
不幸的是覆盖语句 args [i] = null;
现在可以正常工作!有谁知道我应该怎么覆盖它?
Unfortunately the overwrite statement args[i] = null;
does now work! Do anyone know how should I overwrite it?
干杯,
Kevin
推荐答案
我相信你必须实施一个周围的建议,而不是之前的建议。
I believe you have to implement an around advice, instead of a before advice.
因为你可以继续使用你的新参数:
Because you can use proceed with your new arguments:
proceed(newArgs);
这篇关于Aspectj覆盖方法的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文