David Parks
David Parks

Reputation: 32111

SpringMVC: Can I specify a @ModelAttribute be populated only for specific controller methods?

We have a couple of attributes that are common to 90% of the pages in our webapp.

I'd like to simply declare an @ModelAttribute("userCredits") on my controller to populate this common attribute.

However, for some pages I don't need this attribute. Can I avoid it being populated (it's modestly expensive to generate) in the one-off cases when it's not required?

I'm not a big fan of it being populated non-declaratively on every call, but I don't like the copy-paste addition of methods in each controller-handler to populate it either.

Upvotes: 1

Views: 391

Answers (1)

Johan Sjöberg
Johan Sjöberg

Reputation: 49237

I'm pretty confident there is no such support, which is also supported by observing the available annotations from the spring javadoc

Upvotes: 2

Related Questions