From 193bfc65574619ca58c92b11bca967e23bd7b33c Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期日, 26 六月 2022 10:43:49 +0800 Subject: [PATCH] 升级fastjson到最新版2.0.8 --- src/main/java/com/ruoyi/common/utils/ServletUtils.java | 66 +++++++++++++++++++++++++++++---- 1 files changed, 58 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/ruoyi/common/utils/ServletUtils.java b/src/main/java/com/ruoyi/common/utils/ServletUtils.java index 9e6fd59..1cbf72f 100644 --- a/src/main/java/com/ruoyi/common/utils/ServletUtils.java +++ b/src/main/java/com/ruoyi/common/utils/ServletUtils.java @@ -1,12 +1,16 @@ package com.ruoyi.common.utils; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; +import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.text.Convert; /** @@ -49,6 +53,22 @@ } /** + * 鑾峰彇Boolean鍙傛暟 + */ + public static Boolean getParameterToBool(String name) + { + return Convert.toBool(getRequest().getParameter(name)); + } + + /** + * 鑾峰彇Boolean鍙傛暟 + */ + public static Boolean getParameterToBool(String name, Boolean defaultValue) + { + return Convert.toBool(getRequest().getParameter(name), defaultValue); + } + + /** * 鑾峰彇request */ public static HttpServletRequest getRequest() @@ -83,9 +103,8 @@ * * @param response 娓叉煋瀵硅薄 * @param string 寰呮覆鏌撶殑瀛楃涓� - * @return null */ - public static String renderString(HttpServletResponse response, String string) + public static void renderString(HttpServletResponse response, String string) { try { @@ -98,7 +117,6 @@ { e.printStackTrace(); } - return null; } /** @@ -109,13 +127,13 @@ public static boolean isAjaxRequest(HttpServletRequest request) { String accept = request.getHeader("accept"); - if (accept != null && accept.indexOf("application/json") != -1) + if (accept != null && accept.contains("application/json")) { return true; } String xRequestedWith = request.getHeader("X-Requested-With"); - if (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1) + if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest")) { return true; } @@ -127,10 +145,42 @@ } String ajax = request.getParameter("__ajax"); - if (StringUtils.inStringIgnoreCase(ajax, "json", "xml")) + return StringUtils.inStringIgnoreCase(ajax, "json", "xml"); + } + + /** + * 鍐呭缂栫爜 + * + * @param str 鍐呭 + * @return 缂栫爜鍚庣殑鍐呭 + */ + public static String urlEncode(String str) + { + try { - return true; + return URLEncoder.encode(str, Constants.UTF8); } - return false; + 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