'StringBuilder' can be replaced with 'String'.

feature/net-util
ZhouXY108 2023-07-19 18:26:35 +08:00
parent 02febda345
commit aacfac630c
2 changed files with 17 additions and 35 deletions

View File

@ -26,12 +26,7 @@ public class JdbcSql extends SQL<JdbcSql> {
}
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<JdbcSql> {
}
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) {

View File

@ -26,40 +26,32 @@ public class MyBatisSql extends SQL<MyBatisSql> {
}
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("<foreach item=\"")
.append(col)
.append("\" index=\"index\" collection=\"")
.append(paramName)
.append("\" open=\"(\" separator=\",\" close=\")\">")
.append("#{")
.append(col)
.append("}</foreach>")
.toString();
final String format = "<foreach" +
" item=\"%s\"" +
" index=\"index\"" +
" collection=\"%s\"" +
" open=\"(\"" +
" separator=\",\"" +
" close=\")\"" +
">" +
"#{%s}" +
"</foreach>";
return String.format(format, col, paramName, col);
}
@Override
public String toString() {
String str = super.toString();
if (withScript) {
str = "<script>\n" + str + "\n</script>";
return "<script>\n" + super.toString() + "\n</script>";
}
return str;
return super.toString();
}
}