Java Spring aop(ControllerAdvice和ModelAttribute中的自定义参数)
我想向ControllerAdvice和ModelAttribute方法添加自定义参数。请参阅下面的代码Java Spring aop(ControllerAdvice和ModelAttribute中的自定义参数),java,spring,aop,modelattribute,Java,Spring,Aop,Modelattribute,我想向ControllerAdvice和ModelAttribute方法添加自定义参数。请参阅下面的代码 @Target( { ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface MyPage { String param(); } @Controller public class MyController { @RequestMapping... @MyPage(param
@Target( { ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface MyPage {
String param();
}
@Controller
public class MyController {
@RequestMapping...
@MyPage(param = "a")
public void myPage() {
....
}
}
@ControllerAdvice
public class MyAdviceController {
@ModelAttribute
public void addAttributes(Model model, MyPage myPage){
System.out.println(myPage.param());
}
}
如何让myPage参数工作。
我越来越
class org.springframework.beans.BeanInstantiationException
Exception: Could not instantiate bean class [MyPage]: Specified class is an interface
我想获取参数值为a的myPage对象您试图用此构造实现的最终结果是什么?ModelAttribute方法为每个请求处理程序获取调用。我想获取参数值为aXY的myPage对象。这就是你想要的。我们想知道为什么。