一、从request中读出cookies集合,然后封装成map,为的是能够直接通过name得到相应的cookie即get方法
public static Cookie get(HttpServletRequest request, String name) { Map<String, Cookie> cookieMap = readCookieMap(request); if (cookieMap.containsKey(name)) { return cookieMap.get(name); }else { return null; }} /** * 将cookie封装成Map * @param request * @return */private static Map<String, Cookie> readCookieMap(HttpServletRequest request) { Map<String, Cookie> 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
时间: 2024-10-06 16:07:41