Trying to match an AspectJ pointcut signature for any methods containing a variable

南楼画角 提交于 2020-01-03 17:12:26

问题


I want to create a pointcut that matches any method in my Web controller that contains a ModelMap:

pointcut addMenu(ModelMap modelMap) : 
    execution (public String example.web.MyController.*(..)) && args (modelMap);

before(ModelMap modelMap) : addMenu(modelMap) {
    // Do stuff with modelMap...
}

My problem is that this only matches methods with ONLY the ModelMap parameter, others are not matched because they contain too many parameters. For example, this is not intercepted, due to the "req" parameter:

public String request(HttpServletRequest req, ModelMap modelMap) {
    // Handle request
}

Is there any way to match all methods with a ModelMap parameter, without having to add a pointcut delegate for every possible parameter combination?


回答1:


You can use wildcards * or .. to express the arguments in a flexible way.

pointcut addMenu(ModelMap modelMap) : 
    execution (public String example.web.MyController.*(..)) && args (*, modelMap);

See AspectJ: parameter in a pointcut



来源:https://stackoverflow.com/questions/2222911/trying-to-match-an-aspectj-pointcut-signature-for-any-methods-containing-a-varia

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!