spring mvc:在非@Controller 端点上应用@ModelAttribute
spring mvc: applying @ModelAttribute on non-@Controller endpoints
我已阅读 了解如何在全局范围内向模型注入参数。我的理解是否正确,这种方法不会涵盖由例如呈现的视图<mvc:view-controller>
,或 form-login
自定义登录页面?
如果是这样,有没有办法扩展这种机制以包括所有视图?
谢谢
最终使用 Interceptor, as laid-out in this reply. Registered interceptor to intercept all non-resource endpoints (using mvc:exclude-mapping).
public class HandlerInterceptor extends HandlerInterceptorAdapter {
@Override
public void postHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler,
ModelAndView modelAndView) throws Exception {
if (modelAndView == null)
return;
modelAndView.addObject("foo", "bar");
}
我已阅读 <mvc:view-controller>
,或 form-login
自定义登录页面?
如果是这样,有没有办法扩展这种机制以包括所有视图?
谢谢
最终使用 Interceptor, as laid-out in this reply. Registered interceptor to intercept all non-resource endpoints (using mvc:exclude-mapping).
public class HandlerInterceptor extends HandlerInterceptorAdapter {
@Override
public void postHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler,
ModelAndView modelAndView) throws Exception {
if (modelAndView == null)
return;
modelAndView.addObject("foo", "bar");
}