代码优化

This commit is contained in:
thinkgem
2025-10-10 20:56:06 +08:00
parent 91bfc7a7c9
commit 75f51fa221

View File

@@ -16,6 +16,8 @@ import jakarta.servlet.ServletRequest;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.util.AntPathMatcher; import org.springframework.util.AntPathMatcher;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
@@ -32,6 +34,8 @@ import java.util.Map.Entry;
*/ */
public class ServletUtils { public class ServletUtils {
private static final Logger logger = LoggerFactory.getLogger(ServletUtils.class);
public static final String EXT_PARAMS_PREFIX = "param_"; // 扩展参数前缀 public static final String EXT_PARAMS_PREFIX = "param_"; // 扩展参数前缀
// 定义静态文件后缀静态文件排除URI地址 // 定义静态文件后缀静态文件排除URI地址
@@ -107,7 +111,7 @@ public class ServletUtils {
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
@@ -121,7 +125,7 @@ public class ServletUtils {
throw new Exception("检测到“application.yml”中没有配置“web.staticFile”属性。配置示例\n#静态文件后缀\nweb.staticFile=" + throw new Exception("检测到“application.yml”中没有配置“web.staticFile”属性。配置示例\n#静态文件后缀\nweb.staticFile=" +
".css,.js,.map,.png,.jpg,.gif,.jpeg,.webp,.bmp,.ico,.swf,.psd,.htc,.crx,.xpi,.exe,.ipa,.apk,.otf,.eot,.svg,.ttf,.woff,.woff2"); ".css,.js,.map,.png,.jpg,.gif,.jpeg,.webp,.bmp,.ico,.swf,.psd,.htc,.crx,.xpi,.exe,.ipa,.apk,.otf,.eot,.svg,.ttf,.woff,.woff2");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
if (StringUtils.containsAny(uri, STATIC_FILE_EXCLUDE_URI)) { if (StringUtils.containsAny(uri, STATIC_FILE_EXCLUDE_URI)) {
@@ -363,7 +367,7 @@ public class ServletUtils {
} }
response.getWriter().print(string); response.getWriter().print(string);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }