我有一个HandlerInterceptorAdaptor.preHandle()方法,简化如下:
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
request.setAttribute("MyObject", myObject);
return true;
}
接下来当我的@RestController
被调用时,我希望它看起来像这样:
@RequestMapping(value="/", method=RequestMethod.PUT)
public ResponseEntity myMethod (MyObject myObject) {
}
我想有一些注释我可以放在那里,Spring将添加我之前在HandlerInterceptorAdaptor中设置的属性。
有人可以告诉我那是什么意思吗?
答案 0 :(得分:3)
为什么不喜欢这个?
@RequestMapping(value="/", method=RequestMethod.PUT)
public ResponseEntity myMethod (HttpServletRequest request, HttpServletResponse response) {
MyClass obj = (MyClass) request.getAttribute("myObject");
}