@RequestAttribute
in a Spring MVC project doesn't fetch the value.
I use a @ModelAttribute. Here foo
attribute is set a value of bar
@ModelAttribute
void beforeInvokingHandlerMethod(HttpServletRequest request)
{
request.setAttribute("foo", "bar");
}
I try to invoke the request attribute value for foo
using @RequestAttribute("foo")
. But value is null.
Then I try using request.getAttribute("foo")
and the value is printed. I don't know what is wrong in the following code:
@RequestAttribute("foo").
@RequestMapping(value="/data/custom", method=RequestMethod.GET)
public @ResponseBody String custom(@RequestAttribute("foo") String foo, HttpServletRequest request) {
System.out.println("foo value : " + foo); //null printed
System.out.println("request.getAttribute : " + request.getAttribute("foo")); //value printed
return foo;
}