3

I have a HandlerInterceptorAdaptor.preHandle() method that simplified looks like this:

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {        
    request.setAttribute("MyObject", myObject);

    return true;
}

Next when my @RestController gets called, I would like it to look like this:

@RequestMapping(value="/", method=RequestMethod.PUT)
public ResponseEntity myMethod (MyObject myObject) {

}

I imagine there is some annotation I can put there where Spring will add the attribute I set earlier in the HandlerInterceptorAdaptor.

Could someone please tell me what that is?

1
  • What is the use case? Does myObject enrich the existing request body or just an additional metadata? Commented Nov 26, 2015 at 5:24

1 Answer 1

4

Why not like this?

@RequestMapping(value="/", method=RequestMethod.PUT)
public ResponseEntity myMethod (HttpServletRequest request, HttpServletResponse response) {
     MyClass obj = (MyClass) request.getAttribute("myObject");
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.