StringBuilder.append
对于大型SQL语句看起来很难看,格式化要追加需要花费很多时间才能在Java中格式化StringBuilder
/ StringBuffer
答案 0 :(得分:2)
String.format
可能有助于提高代码的可读性:
String sql = String.format("select * from %s where %s = ?;", table, field);
StringBuilder
替代方案:
String sql = new StringBuilder("select * from ")
.append(table)
.append(" where ")
.append(field)
.append(" = ")
.append("?")
.toString();