I want to implement a dynamically changing menu (updating whenever an annotated method or controller is added) for my Spring MVC application.
I want to introduce a new annotation ( @RequestMenuMapping ) that will go to @Controller beans, and their methods (like @RequestMapping work).
Heres is what I want, a User class creating a menu like
Users Index | List | Signup | Login
with the following code:
@Controller @RequestMapping("user") @RequestMenuMapping("Users") public class User { @RequestMapping("") @RequestMenuMapping("Index") public String index() { return "user/index.tile"; } @RequestMapping("list") @RequestMenuMapping("List") public String list(Model model) { model.addAttribute("userList",); return "user/list.tile"; } @RequestMapping("signup") @RequestMenuMapping("Signup") public String signup(Model model) { model.addAttribute("user",); return "user/signup.tile"; } @RequestMapping("login") @RequestMenuMapping("Login") public String login(Model model) { model.addAttribute("userCreds",); return "user/login.tile"; } }
I think Spring AOP can help me specify methods with the @RequestMenuMapping annotation @RequestMenuMapping and through @AfterReturning add something that represents the website menu for modeling.
But this raises two questions:
- How can I get an instance of
Model in the @AfterReturning method if it is not in the adviced method (as in .index() )? - How can I get all methods (like in java reflection
Method ) and classes (like in java reflection Class ) annotated with @RequestMenuMapping in order to build a full menu index?
source share