控制器方法的Spring AOP传递参数 [英] Spring AOP pass argument of a controller method
本文介绍了控制器方法的Spring AOP传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个如下的控制器
@Controller
@RequestMapping(value = "/")
public class HomeController {
@RequestMapping("/")
public String home(Map<String,Object> map) {
map.put("val2","val2");
return "mainpage"; //it is the jsp file name
}
}
现在,在我的Aspect类方法中,我想在控制器方法中定义的此map变量中放置另一个值
Now In my aspect class method I want to put another value in this map variable defined in the controller method
@Aspect
public class UserInfo {
@Before("execution(* org.controller.HomeController(..)) ")
public void m1(){
//Map<String,Object> map
// get the map here and add
map.put("val1","val1);
}
}
这样,当我调用此地图表单mainpage.jsp文件时,我得到的两个值都是
so that when i call this map form mainpage.jsp file I get both value as
${val1}
${val2}
我该怎么做?
推荐答案
您可以在JoinPoint上使用getArgs来获取方法的参数,例如:
You could use getArgs on JoinPoint to get the argument to the method like:
Object[] signatureArgs = joinPoint.getArgs();
您的m1方法应类似于:
Your m1 method should be like:
public void m1(JoinPoint joinPoint){
您已经知道该方法仅具有on参数,因此您需要将其类型转换为映射,然后放入新值并调用proce方法以继续进行实际的调用.
You already know that you just have on argument to the method, so you would need to type cast it to a map and then put your new values and call proceed method to proceed with further actual call.
这篇关于控制器方法的Spring AOP传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文