Spring Controllers: Can I call a method before each @RequestMapping method is called?
问题 I have some common components that are always present in every page served by a given Controller class. At the beginning of each @RequestMapping method I populate the model with these common components. Is there a way to define a method be called prior to each of the controller methods so that I can get all of this copy/paste into one place? 回答1: Just annotate a method with @ModelAttribute The below would add a Foo instance to the model under the name "foo" @ModelAttribute("foo") public Foo