From 1f42bd3d22c104aaa2d780c20a555b5e467858bf Mon Sep 17 00:00:00 2001 From: MichelleChung <1242874891@qq.com> Date: 星期一, 07 十一月 2022 22:10:52 +0800 Subject: [PATCH] !245 数据源由 Druid 修改为 Hikari * update 更新 dataSource 数据源, 由 druid 修改为 hikari, 更新相关配置 ; --- ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java | 45 ++++++++++++++++++++++++++++++++++++--------- 1 files changed, 36 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..7012a01 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; @@ -14,6 +15,9 @@ 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; /** @@ -97,9 +101,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 +111,6 @@ } catch (IOException e) { e.printStackTrace(); } - return null; } /** @@ -119,12 +121,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 +136,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