我希望为我的
Spring MVC应用程序实现动态可更改的菜单(无论何时添加带注释的方法或控制器).
我想要的是引入新的注释(@RequestMenuMapping),它将转到@Controller bean及其方法(就像@RequestMapping一样).
Heres是我想要的,User类,生成菜单之类的
Users
Index | List | Signup | Login
使用以下代码:
@Controller
@RequestMapping("user")
@RequestMenuMapping("Users")
public class User {
@RequestMapping("")
@RequestMenuMapping("Index")
public String index(/* no model here - just show almost static page (yet with JSP checks for authority)*/) {
return "user/index.tile";
}
@RequestMapping("list")
@RequestMenuMapping("List")
public String list(Model model) {
model.addAttribute("userList",/* get userlist from DAO/Service */);
return "user/list.tile";
}
@RequestMapping("signup")
@RequestMenuMapping("Signup")
public String signup(Model model) {
model.addAttribute("user",/* create new UserModel instance to be populated by user via html form */);
return "user/signup.tile";
}
@RequestMapping("login")
@RequestMenuMapping("Login")
public String login(Model model) {
model.addAttribute("userCreds",/* create new UserCreds instance to be populated via html form with login and pssword*/);
return "user/login.tile";
}
}
我认为Spring AOP可以帮助我使用@RequestMenuMapping注释切入方法,并通过@AfterReturning将代表网站菜单的内容添加到模型中.
但这提出了两个问题:
>如果在adviced方法中缺少(如.index()),我如何在@AfterReturning建议方法中获取Model实例?
>我如何获得所有方法(如在java反射方法中)和使用@RequestMenuMapping注释的类(如在java反射类中)以构建完整的菜单索引?