How can I run common code for most requests in my Spring MVC Web App?

前端 未结 3 2093
清歌不尽
清歌不尽 2021-02-09 15:00

i.e.

I have various URLs mapped using Spring MVC RequestMapping

@RequestMapping(value = \"/mystuff\", method = RequestMethod.GET) 
@RequestMapping(value          


        
3条回答
  •  耶瑟儿~
    2021-02-09 15:39

    The HandlerInterceptor.preHandle() method gives you access to the request and response and also the target handler. In Spring 3.1 that will be of type HandlerMethod, which gives you access to the target controller class and method. If it helps you can try excluding entire controller classes by type name, which would be strongly typed and without specifying explicit URLs.

    Another option would be created an interceptor mapped to a set of URL patterns. See the section on configuring Spring MVC in the reference documentation.

提交回复
热议问题