您可以在 postHandle 中使用拦截器来执行此操作:
public class DefaultModelInterceptor extends HandlerInterceptorAdapter {
@Override
public void postHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler,
final ModelAndView modelAndView) throws Exception {
modelAndView.addObject("userBO", userBO);
modelAndView.addObject("searchBO", searchBO);
super.postHandle(request, response, handler, modelAndView);
}
}
然后可以将其连接到您的 spring servlet 配置中:
<mvc:interceptors>
<bean class="my.package.DefaultModelInterceptor"/>
</mvc:interceptors>