From b38151a0bb0484221ba7b9ad3a1aa773105e1b14 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期二, 06 十二月 2022 11:32:35 +0800 Subject: [PATCH] !260 单元格合并判断cellValue是否相等方法调整 Merge pull request !260 from zendwang/dev --- ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java | 74 ++++++++++++++++++++++++++++++++---- 1 files changed, 65 insertions(+), 9 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java index 5babaeb..91ddd3f 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java @@ -3,6 +3,7 @@ import cn.hutool.core.convert.Convert; import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.http.HttpStatus; +import com.ruoyi.common.constant.Constants; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.springframework.http.MediaType; @@ -10,11 +11,18 @@ import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; +import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; /** * 瀹㈡埛绔伐鍏风被 @@ -67,6 +75,31 @@ } /** + * 鑾峰緱鎵�鏈夎姹傚弬鏁� + * + * @param request 璇锋眰瀵硅薄{@link ServletRequest} + * @return Map + */ + public static Map<String, String[]> getParams(ServletRequest request) { + final Map<String, String[]> map = request.getParameterMap(); + return Collections.unmodifiableMap(map); + } + + /** + * 鑾峰緱鎵�鏈夎姹傚弬鏁� + * + * @param request 璇锋眰瀵硅薄{@link ServletRequest} + * @return Map + */ + public static Map<String, String> getParamMap(ServletRequest request) { + Map<String, String> params = new HashMap<>(); + for (Map.Entry<String, String[]> entry : getParams(request).entrySet()) { + params.put(entry.getKey(), StringUtils.join(entry.getValue(), ",")); + } + return params; + } + + /** * 鑾峰彇request */ public static HttpServletRequest getRequest() { @@ -97,9 +130,8 @@ * * @param response 娓叉煋瀵硅薄 * @param string 寰呮覆鏌撶殑瀛楃涓� - * @return null */ - public static String renderString(HttpServletResponse response, String string) { + public static void renderString(HttpServletResponse response, String string) { try { response.setStatus(HttpStatus.HTTP_OK); response.setContentType(MediaType.APPLICATION_JSON_VALUE); @@ -108,7 +140,6 @@ } catch (IOException e) { e.printStackTrace(); } - return null; } /** @@ -119,12 +150,12 @@ public static boolean isAjaxRequest(HttpServletRequest request) { String accept = request.getHeader("accept"); - if (accept != null && accept.indexOf("application/json") != -1) { + if (accept != null && accept.contains(MediaType.APPLICATION_JSON_VALUE)) { return true; } String xRequestedWith = request.getHeader("X-Requested-With"); - if (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1) { + if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest")) { return true; } @@ -134,14 +165,39 @@ } String ajax = request.getParameter("__ajax"); - if (StringUtils.equalsAnyIgnoreCase(ajax, "json", "xml")) { - return true; - } - return false; + return StringUtils.equalsAnyIgnoreCase(ajax, "json", "xml"); } public static String getClientIP() { return getClientIP(getRequest()); } + /** + * 鍐呭缂栫爜 + * + * @param str 鍐呭 + * @return 缂栫爜鍚庣殑鍐呭 + */ + public static String urlEncode(String str) { + try { + return URLEncoder.encode(str, Constants.UTF8); + } catch (UnsupportedEncodingException e) { + return StringUtils.EMPTY; + } + } + + /** + * 鍐呭瑙g爜 + * + * @param str 鍐呭 + * @return 瑙g爜鍚庣殑鍐呭 + */ + public static String urlDecode(String str) { + try { + return URLDecoder.decode(str, Constants.UTF8); + } catch (UnsupportedEncodingException e) { + return StringUtils.EMPTY; + } + } + } -- Gitblit v1.9.3