开发者

Is it possible to run code before Spring Framework controller method is called?

I'm creating menu and I would like to link my menu items to Spring controller paths. One way to do this is to include menu code to all methods that contain @RequestMapping annotations, but it would be manual task, I would like to automate this task, so that I could just def开发者_运维知识库ine menu bean and add menu in site template and menus would be generated automatically for every path.


SpringMVC Interceptors might be a bit easier than the straight AOP above.

  • Spring Reference
  • Sample Config

Note: This approach does couple the code a bit more to Spring MVC, but it'd be an easy port to a similar interception/aspect application in any other framework


It doesn't have to be a manual task. You can easily add menu code to all methods that contain @RequestMapping annotations by using AOP. Here are the docs http://static.springsource.org/spring/docs/2.5.x/reference/aop.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜