spring mvc annotation @RequestAttribute similar to

2019-08-12 15:28发布

问题:

I would like add an annotation similar to @RequestParam, though have it pull the values from the request attribute rather than the request param...

Is there an example or explanation how to create my own annotation for this and the handler / binder needed as well?

Thanks

回答1:

The blog entry with the title "Extending Spring MVC's annotation controller" answers your question. Google it to find it since Stackoverflow won't let me create the direct link.

Basically you create an @RequestAttribute annotation and then a custom WebArgumentResolver.

The blog entry has examples for @RequestAttribute and @SessionAttribute.

The svn directory with the examples is here.

http://impala-extensions.googlecode.com/svn/trunk/impala-extension-mvc/src/org/impalaframework/extension/mvc/



回答2:

Since Spring 4.3 @RequestAttribute annotation is a part of Spring MVC, so there is no need to create your own @RequestAttribute annotation