【fix sonar】 CookieUtil.java文件

This commit is contained in:
tianwenbo
2023-03-10 15:59:27 +08:00
parent f3c58c93fa
commit 60ebd626db
@@ -15,14 +15,17 @@ public class CookieUtil {
private static final int COOKIE_MAX_AGE = Integer.MAX_VALUE; private static final int COOKIE_MAX_AGE = Integer.MAX_VALUE;
// 保存路径,根路径 // 保存路径,根路径
private static final String COOKIE_PATH = "/"; private static final String COOKIE_PATH = "/";
private CookieUtil() {
}
/** /**
* 保存 * 保存
* *
* @param response * @param response
* @param key * @param key
* @param value * @param value
* @param ifRemember * @param ifRemember
*/ */
public static void set(HttpServletResponse response, String key, String value, boolean ifRemember) { public static void set(HttpServletResponse response, String key, String value, boolean ifRemember) {
int age = ifRemember?COOKIE_MAX_AGE:-1; int age = ifRemember?COOKIE_MAX_AGE:-1;
@@ -47,7 +50,7 @@ public class CookieUtil {
cookie.setHttpOnly(isHttpOnly); cookie.setHttpOnly(isHttpOnly);
response.addCookie(cookie); response.addCookie(cookie);
} }
/** /**
* 查询value * 查询value
* *
@@ -70,9 +73,9 @@ public class CookieUtil {
* @param key * @param key
*/ */
private static Cookie get(HttpServletRequest request, String key) { private static Cookie get(HttpServletRequest request, String key) {
Cookie[] arr_cookie = request.getCookies(); Cookie[] arrCookie = request.getCookies();
if (arr_cookie != null && arr_cookie.length > 0) { if (arrCookie != null && arrCookie.length > 0) {
for (Cookie cookie : arr_cookie) { for (Cookie cookie : arrCookie) {
if (cookie.getName().equals(key)) { if (cookie.getName().equals(key)) {
return cookie; return cookie;
} }
@@ -80,7 +83,7 @@ public class CookieUtil {
} }
return null; return null;
} }
/** /**
* 删除Cookie * 删除Cookie
* *
@@ -95,4 +98,4 @@ public class CookieUtil {
} }
} }
} }