controller 인터페이스에 접근하기 전에 수정 방법을 입력하십시오. 파라미터는 대상입니다. (예: @@RequestBody HttpHeaders headers)
1625 단어 springAop
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* @Author: NJ
* @Description: , header
* @Date: 2019/8/28
*/
@Component
@Aspect
public class AnnotationAspect {
@Pointcut("@annotation(com.annotation.ChangeHeader)")
private void cutMethod() {
}
/**
* , header @ChangeHeader header
* controller
* @param pjp
* @return
* @throws Throwable
*/
@Around("cutMethod()")
public Object changeHeader(ProceedingJoinPoint pjp) throws Throwable{
//
Object[] args = pjp.getArgs();
ReturnMsg returnMsg = new ReturnMsg<>();
try {
for(int i = 0; i < args.length; i++){
if(args[i] instanceof HttpHeaders){
HttpHeaders paramValue = (HttpHeaders)args[i];
/** **/
paramValue.set("loginUserName",“ header ”);
/** **/
args[i] = paramValue;
}
}
}catch (Exception e){
/** , json **/
e.printStackTrace();
returnMsg.handleException(e);
return returnMsg;
}
/** , **/
Object retVal = pjp.proceed(args)
return retVal;
}
}
@Pointcut("execution(public * com..project.web..*(..))")
controller,