开发者

Overwrite Interceptor ModelAndView in Spring MVC

开发者 https://www.devze.com 2023-04-03 01:35 出处:网络
I am trying to set a global title for my webpage inside Sring MVC Interceptor posthandle method like so

I am trying to set a global title for my webpage inside Sring MVC Interceptor posthandle method like so

Interceptor Class

model.addObject("title", "global title"); //ModelAndView

T开发者_JAVA百科hen in my controller class I have

model.addAttribute("title", "Specific page title"); //Model - Overwrite global title

my jsp header

<title>${titile}</title>

The problem is that I always get the "global title" as a value for the title variable. For some reason, the model ui inside the controller never overwrote the one that being set inside the interceptor.


If I understand correctly, you implement HandlerInterceptor.postHandle() method. PostHandle means, this is run after the individual controller has been run. Since you are setting the title attribute after the individual handler has tun to "global title", you will always get "global title".

Try HandlerInterceptor.preHandle() - there is a chance this would work better I think...

(EDIT: typed nonsense... try preHandle(), not try postHandle())

0

精彩评论

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