From aacfac630c7730aa202df2b8bdd77fdb27ba0e7c Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Wed, 19 Jul 2023 18:26:35 +0800 Subject: [PATCH] 'StringBuilder' can be replaced with 'String'. --- .../zhouxy/plusone/commons/sql/JdbcSql.java | 14 +------ .../plusone/commons/sql/MyBatisSql.java | 38 ++++++++----------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/src/main/java/xyz/zhouxy/plusone/commons/sql/JdbcSql.java b/src/main/java/xyz/zhouxy/plusone/commons/sql/JdbcSql.java index 32b71f4..5a1a658 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/sql/JdbcSql.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/sql/JdbcSql.java @@ -26,12 +26,7 @@ public class JdbcSql extends SQL { } private static String IN(String col, int length) { - return new StringBuilder() - .append(col) - .append(" IN (") - .append(buildQuestionsList(length)) - .append(')') - .toString(); + return col + " IN (" + String.valueOf(buildQuestionsList(length)) + ')'; } public static String NOT_IN(String col, Collection c) { @@ -43,12 +38,7 @@ public class JdbcSql extends SQL { } private static String NOT_IN(String col, int length) { - return new StringBuilder() - .append(col) - .append(" NOT IN (") - .append(buildQuestionsList(length)) - .append(')') - .toString(); + return col + " NOT IN (" + String.valueOf(buildQuestionsList(length)) + ')'; } private static char[] buildQuestionsList(int times) { diff --git a/src/main/java/xyz/zhouxy/plusone/commons/sql/MyBatisSql.java b/src/main/java/xyz/zhouxy/plusone/commons/sql/MyBatisSql.java index 8c9e3c1..73f680d 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/sql/MyBatisSql.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/sql/MyBatisSql.java @@ -26,40 +26,32 @@ public class MyBatisSql extends SQL { } public static String IN(String col, String paramName) { - return new StringBuilder(" ") - .append(col) - .append(" IN") - .append(buildQuestionsList(col, paramName)) - .toString(); + return " " + col + " IN" + buildQuestionsList(col, paramName); } public static String NOT_IN(String col, String paramName) { - return new StringBuilder() - .append(col) - .append(" NOT IN") - .append(buildQuestionsList(col, paramName)) - .toString(); + return col + " NOT IN" + buildQuestionsList(col, paramName); } private static String buildQuestionsList(String col, String paramName) { - return new StringBuilder() - .append("") - .append("#{") - .append(col) - .append("}") - .toString(); + final String format = "" + + "#{%s}" + + ""; + return String.format(format, col, paramName, col); } @Override public String toString() { - String str = super.toString(); if (withScript) { - str = ""; + return ""; } - return str; + return super.toString(); } } \ No newline at end of file