Is there a way to stop Spring from adding in reference data from methods marked with @ModelAttribute into the URL on redirects?
I'm currently using the @ModelAttribute 开发者_如何学JAVAannotation in my controllers to add reference data to my pages and forms, ie:
@ModelAttribute("someValue")
public String getSomeValue() {
return someValue;
}
This works great until I start using redirects from the controllers. All of the values from methods marked with @ModelAttribute appear in the URL, ie:
http://somedomain.com/page?someValue=value
Is there a setting to turn this off? Or is there a simple fix for this?
I read something about creating an interceptor for adding reference data into a model, but that just seems wrong:
http://developingdeveloper.wordpress.com/2008/02/28/common-reference-data-in-spring-mvc/
I found out that there is a setter on the RedirectView object called setExposeModelAttributes. If you set it to false, the attributes don't get thrown into the URL.
I got some help from PUK_999 in the spring source forums:
http://forum.springsource.org/showpost.php?p=274948&postcount=6
This is intentional and specific behaviour of @ModelAttribute
, even if it does feel wrong and broken.
An interceptor is really one of the easiest ways of doing this.
精彩评论