设置了拦截器时候,我的账号传不进数据库
我也踩过这个坑( 1 )
详细描述
错误截图
源码
编辑于2024-11-24
-
[成都|荣耀师兄]JAVA-先小波0
prehandle要return true,不然是不会进行后面的操作的。下面是我的拦截器的例子:
@Component
public class LoginInterceptor implements HandlerInterceptor {
private static Logger log = Logger.getLogger(LoginInterceptor.class);
@Autowired
private CookieUtil cookieUtil;
@Autowired
private JwtUtil jwtUtil;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,Object handler) throws Exception{
String JwtToken = cookieUtil.getCookie(request);
if(JwtToken == null) {
response.sendRedirect("/a/login");
return false;
}
Integer userId = jwtUtil.getUserId(JwtToken);
if(userId == null){
response.sendRedirect("/a/login");
return false;
}
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception{
// System.out.println("postHandle");
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
// System.out.println("afterCompletion");
}
}编辑于2018-12-03
- 去第 页