How can assign multi parameters to the args in spring AOP pointcut

283 Views Asked by At

I wrote pointcut like this for the target method aaa. I want to enroll whole parameters of target method to the advice method's parameters. Could you let me know how can I make it.

  • target method
fun aaa(    
        @RequestParam(value = "startDate")
        @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) startDate: LocalDate,
        @RequestParam(value = "endDate")
        @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) endDate: LocalDate,
        @ModelAttribute privateInfoRequestDTO: PrivateInfoRequestDTO,
        request: HttpServletRequest
    )
  • advice method's pointcut
@Before("@annotation(com.blah.blah...) && args(privateInfoRequestDTO, startDate, endDate, request)")
1

There are 1 best solutions below

0
kriegaex On

Try JoinPoint.getArgs, if you need a generic solution matching any numbers and types of parameters.

If you know the relative positions from left or right of the parameters you wish to bind using args(...), such as 1st parameter, 2nd-last parameter etc., of course it is more comfortable and type-safe to stick with args.

Please also read some documentation before asking questions on StackOverflow next time. Thanks.