簡體   English   中英

如何使用帶參數化的注釋指定方法,並通過@Pointcut指定其值

[英]How can I specify method with an parameterized annotation and its value with @Pointcut

背景:

我正在用Spring MVC開發一個Web應用程序。

我想使一個方面在POST請求上執行,而不在GET請求上執行,因為我想注入阻止在HTML呈現完成之前發送的POST請求的邏輯。

@RequestMapping(value = "/aaa", method = RequestMethod.POST)
public String methodForPost(AnDto dto, Model model) {
    // the aspect should be executed on this method
}

@RequestMapping(value = "/bbb", method = RequestMethod.GET)
public String methodForGET(AnDto dto, Model model) {
    // the aspect shouldn't be executed on this method
}

題:

  1. 如何使用帶參數化的注釋指定方法,並通過@Pointcut指定其值?
  2. 如何在Spring applicationContext.xml <aop:pointcut>中指定帶有參數化批注的方法及其值?
@Around(value="@annotation(RequestMapping)")
public Object display(ProceedingJoinPoint joinPoint, RequestMapping requestMapping ) throws Throwable {
    // You have access to requestMapping. From which you can get whether its get or post and decide to proceed or not.
}

更多信息http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html#aop-ataspectj-advice-params-passing

您可能需要擴展它以僅攔截包中的Requestmapping。 因為這會攔截項目中您可能擁有的每個RequestMappig,包括您可能正在使用的庫所使用的每個RequestMappig,這是一個負擔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM