From f3c6513d5ae0d5dc8f4bf2c8625d7edb85b7521d Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期五, 13 一月 2023 18:43:40 +0800 Subject: [PATCH] add 新增 flatten-maven-plugin 插件统一版本号管理 --- ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java | 77 ++++++++++++++++++++++++++++++++++---- 1 files changed, 68 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 1e1db37..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,22 +3,33 @@ 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; import org.springframework.web.context.request.RequestAttributes; 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; /** * 瀹㈡埛绔伐鍏风被 * * @author ruoyi */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class ServletUtils extends ServletUtil { /** @@ -64,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() { @@ -94,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); @@ -105,7 +140,6 @@ } catch (IOException e) { e.printStackTrace(); } - return null; } /** @@ -116,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; } @@ -131,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