我們從前臺往后臺傳值的時候,傳的可能是一個加密后的字符串,但是不希望后臺的controller類直接獲得是這個加密字符串,而是解密后的字符串。這個時候怎么辦呢?可以增加一個aop來處理
@Component
@Aspect
@Order(10000) //order的值越小越優先執行
public class SecurityAspect {
@Autowired
private HttpServletRequest request; // 簡單的注入request
@Pointcut("execution(@org.springframework.web.bind.annotation.RequestMapping * *(..))")
public void aspect() {
}
@Around(value = "aspect() and execution(* create(..)))")
public Object aroundCreate(ProceedingJoinPoint joinPoint) throws Throwable {
Object[] params = joinPoint.getArgs();
params[0] = 解密(param[0]); // 這里解密第一個參數
return joinPoint.proceed(params);
}
}