spring boot项目之登出删除缓存session至redis和cookies

一、从request中读出cookies集合,然后封装成map,为的是能够直接通过name得到相应的cookie即get方法

public static Cookie get(HttpServletRequest request,
String name) {
Map cookieMap = readCookieMap(request);
if (cookieMap.containsKey(name)) {
return cookieMap.get(name);
}else {
return null;
}
}

/**
* 将cookie封装成Map
* @param request
* @return
*/
private static Map readCookieMap(HttpServletRequest request) {
Map cookieMap = new HashMap<>();
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie: cookies) {
cookieMap.put(cookie.getName(), cookie);
}
}
return cookieMap;
}

二、在SellUserController类中的logout方法中调用CookieUtil.get()读取cookie

然后清除redis和cookie

 

 
  

转载于:https://www.cnblogs.com/bozzzhdz/p/9665305.html

你可能感兴趣的:(spring boot项目之登出删除缓存session至redis和cookies)