优雅的拼装SQL

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

insert

String[] columns = {};
String sql = "INSERT INTO %s(%s) VALUES(%s)";
sql = String.format(sql, tableName, StringUtils.join(columns, ","), StringUtils.repeat("?", ",", columns.length));

update

String[] columns = {};
String sql = "UPDATE %s SET %s WHERE %s=?";
sql = String.format(sql, tableName, StringUtils.join(columns, "=?,") + "=?", pkCol);

selectByPk(hibernate传递参数方式)

String[] columns = {};
String sql = "SELECT %1$s FROM %2$s WHERE %3$s IN (:%3$s)";
sql = String.format(sql, StringUtils.join(columns, ","), tableName, pkCol);

转载于:https://my.oschina.net/jackzlz/blog/487925

你可能感兴趣的:(优雅的拼装SQL)