SpringMVC中的
WebRequestInterceptor,postHandle方法
if (Controller带参数ModelMap) {
if (Controller带参数HttpServletResponse) {
if (Controller带参数HttpServletResponse) {
if (ModelMap在Controller结束前没有添加Attribute) { //即ModelMap还是为{}的话,
进入WebRequestInterceptor的postHandle方法中,获取到的ModelMap为null。
}
else if (
ModelMapController结束前添加了Attribute
){
在postHandle中获取到的ModelMap不为null。
}
} else {
在postHandle中获取到的ModelMap不为null。
}
}
但是在
postHandle方法中添加ModelMap的Attribute属于常规做法吗?而确实可以这么实现。
虽然WebRequestInterceptor能够处理ModelMap,但是无法控制跳转页面。
也就是说,如果Interceptor中发生异常,将无法跳转至错误页面。
使用HandlerInterceptorAdapter可以解决这个问题。
但是它的postHandle不支持ModelMap,而是支持ModelAndView。