From 5dce53514609405ad28bad0625c25ad7f2f25cd8 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 29 八月 2024 16:56:43 +0800 Subject: [PATCH] 11 --- se-common/se-common-core/src/main/java/com/se/common/core/utils/StringUtils.java | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-) diff --git a/se-common/se-common-core/src/main/java/com/se/common/core/utils/StringUtils.java b/se-common/se-common-core/src/main/java/com/se/common/core/utils/StringUtils.java index 71c6dc1..3750592 100644 --- a/se-common/se-common-core/src/main/java/com/se/common/core/utils/StringUtils.java +++ b/se-common/se-common-core/src/main/java/com/se/common/core/utils/StringUtils.java @@ -6,7 +6,14 @@ import com.se.common.core.constant.Constants; import com.se.common.core.text.StrFormatter; +import org.springframework.http.HttpCookie; +import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.util.AntPathMatcher; +import org.springframework.util.CollectionUtils; +import org.springframework.util.MultiValueMap; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; /** * 瀛楃涓插伐鍏风被 @@ -605,4 +612,36 @@ } return sb.toString(); } + + public static String getValueFromCookie(ServerHttpRequest request, String key) { + MultiValueMap<String, HttpCookie> cookies = request.getCookies(); + if (CollectionUtils.isEmpty(cookies)) { + return null; + } + + for (Map.Entry<String, List<HttpCookie>> itemList : cookies.entrySet()) { + for (HttpCookie cookie :itemList.getValue()) { + if (cookie.getName().equals(key)){ + return cookie.getValue(); + } + } + } + + return null; + } + + public static String getValueFromCookie(HttpServletRequest request,String key) { + Cookie[] cookies = request.getCookies(); + if (cookies == null || cookies.length == 0) { + return null; + } + + for (Cookie cookie : cookies) { + if (cookie.getName().equals(key)){ + return cookie.getValue(); + } + } + + return null; + } } -- Gitblit v1.9.3