parent
a054dfd571
commit
70d9231c8e
@ -0,0 +1,35 @@
|
||||
package com.example.common.config;
|
||||
|
||||
import com.example.entity.Account;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 拦截器
|
||||
* @author nsw
|
||||
*/
|
||||
public class MyInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse
|
||||
response, Object handler) throws Exception {
|
||||
Account user = (Account) request.getSession().getAttribute("user");
|
||||
if (user == null) {
|
||||
// 重定向到登录页
|
||||
response.sendRedirect("/end/page/login.html");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse
|
||||
response, Object handler, ModelAndView modelAndView) throws Exception {
|
||||
}
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse
|
||||
response, Object handler, Exception ex) throws Exception {
|
||||
}
|
||||
}
|
Loading…
Reference in new issue