优化代码

This commit is contained in:
RuoYi
2022-02-12 14:23:11 +08:00
parent e66f65b257
commit dbca691746
19 changed files with 37 additions and 49 deletions

View File

@@ -18,8 +18,7 @@ public class ExceptionUtil
{
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
String str = sw.toString();
return str;
return sw.toString();
}
public static String getRootErrorMessage(Exception e)

View File

@@ -161,9 +161,8 @@ public class ServletUtils
*
* @param response 渲染对象
* @param string 待渲染的字符串
* @return null
*/
public static String renderString(HttpServletResponse response, String string)
public static void renderString(HttpServletResponse response, String string)
{
try
{
@@ -176,7 +175,6 @@ public class ServletUtils
{
e.printStackTrace();
}
return null;
}
/**
@@ -187,13 +185,13 @@ public class ServletUtils
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;
}
@@ -205,11 +203,7 @@ public class ServletUtils
}
String ajax = request.getParameter("__ajax");
if (StringUtils.inStringIgnoreCase(ajax, "json", "xml"))
{
return true;
}
return false;
return StringUtils.inStringIgnoreCase(ajax, "json", "xml");
}
/**

View File

@@ -55,7 +55,7 @@ public class ImageUtils
/**
* 读取文件为字节数据
*
* @param key 地址
* @param url 地址
* @return 字节数据
*/
public static byte[] readFile(String url)

View File

@@ -944,7 +944,7 @@ public class ExcelUtil<T>
if (StringUtils.isNotEmpty(excel.targetAttr()))
{
String target = excel.targetAttr();
if (target.indexOf(".") > -1)
if (target.contains("."))
{
String[] targets = target.split("[.]");
for (String name : targets)
@@ -1039,7 +1039,7 @@ public class ExcelUtil<T>
for (Object[] os : this.fields)
{
Excel excel = (Excel) os[1];
maxHeight = maxHeight > excel.height() ? maxHeight : excel.height();
maxHeight = Math.max(maxHeight, excel.height());
}
return (short) (maxHeight * 20);
}

View File

@@ -50,9 +50,9 @@ public class SqlUtil
return;
}
String[] sqlKeywords = StringUtils.split(SQL_REGEX, "\\|");
for (int i = 0; i < sqlKeywords.length; i++)
for (String sqlKeyword : sqlKeywords)
{
if (StringUtils.indexOfIgnoreCase(value, sqlKeywords[i]) > -1)
if (StringUtils.indexOfIgnoreCase(value, sqlKeyword) > -1)
{
throw new UtilException("参数存在SQL注入风险");
}