在使用spring aop切面方式拦截方法时,需要使用JoinPoint获取目标方法的参数,这样获得的参数对象中,父类的值是没有被设进去的; 比如:
class A{
private long opusId;
public long getOpusId() { return opusId; }
public void setOpusId(long opusId) { this.opusId = opusId; }
}
class B extends A{
private int replyPlayerId;
public int getReplyPlayerId() {
return replyPlayerId;
}
public void setReplyPlayerId(int replyPlayerId) {
this.replyPlayerId = replyPlayerId;
}
}
function void M1(A a){
...
}
function void M2(B b){
...
}
拦截M1,使用JoinPoint.getArgs()获取目标方法的参数,可以获得传入的值;
但是拦截M2,使用JoinPoint.getArgs()获取目标方法的参数,可以获得传入的值时,只能获得b本身的replyPlayerId值;而不能获得opusId的值;
这个不知道什么原因,获得不到父类的值。只能改代码,拷贝一个A类,在此基础上加一个replyPlayerId属性。
总之,JoinPoint.getArgs()获取目标方法的参数时,不能获得参数父类的值;