mapper拼接类

jingwei
youhong.ai 2023-05-12 21:17:28 +08:00
parent ad6c60dc9f
commit 402082f038
1 changed files with 26 additions and 3 deletions

View File

@ -23,6 +23,17 @@ public class MapperBuilderSql {
* @return sql
*/
public static String builderUpdateSql(String table, Map<String, Object> param) {
return builderUpdateSql(table, param, "");
}
/**
* <h2>sql</h2>
*
* @param table
* @param param
* @return sql
*/
public static String builderUpdateSql(String table, Map<String, Object> param, String paramPrefix) {
if (StrUtil.isBlank(table) || CollectionUtil.isEmpty(param)) {
throw new CustomerException("tableName or param can not to be null!");
}
@ -32,8 +43,11 @@ public class MapperBuilderSql {
sb.append(" ")
.append(entry.getKey())
.append(" = ")
.append("#{")
.append(entry.getKey())
.append("#{");
if (StrUtil.isNotBlank(paramPrefix)) {
sb.append(paramPrefix).append(".");
}
sb.append(entry.getKey())
.append("}")
.append(",");
}
@ -49,6 +63,10 @@ public class MapperBuilderSql {
* @return sql
*/
public static String builderInsertSql(String table, Map<String, Object> param) {
return builderInsertSql(table, param, "");
}
public static String builderInsertSql(String table, Map<String, Object> param, String paramPrefix) {
if (StrUtil.isBlank(table) || CollectionUtil.isEmpty(param)) {
throw new CustomerException("tableName or param can not to be null!");
}
@ -58,7 +76,11 @@ public class MapperBuilderSql {
sbValue.append(") values ( ");
for (Map.Entry<String, Object> entry : param.entrySet()) {
sb.append(entry.getKey()).append(" ,");
sbValue.append(" #{").append(entry.getKey()).append("},");
sbValue.append(" #{");
if (StrUtil.isNotBlank(paramPrefix)) {
sbValue.append(paramPrefix).append(".");
}
sbValue.append(entry.getKey()).append("},");
}
sb.deleteCharAt(sb.length() - 1);
sbValue.deleteCharAt(sbValue.length() - 1);
@ -66,6 +88,7 @@ public class MapperBuilderSql {
return sb.toString();
}
public static String builderWhereAnd(Map<String, Object> param, boolean containsWhere) {
return builderWhereAnd(param, "whereParam", containsWhere);
}