Skip to content

Commit 9acf62b

Browse files
committed
✨ 集成 Jdbc Template,并简易封装通用 Dao 层
1 parent 7fe5bf6 commit 9acf62b

File tree

1 file changed

+3
-3
lines changed
  • spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/orm/jdbctemplate/dao/base

1 file changed

+3
-3
lines changed

spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/orm/jdbctemplate/dao/base/BaseDao.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public Integer insert(T t, Boolean ignoreNull) {
5050
Table tableAnnotation = t.getClass().getAnnotation(Table.class);
5151
String table;
5252
if (ObjectUtil.isNotNull(tableAnnotation)) {
53-
table = tableAnnotation.name();
53+
table = StrUtil.format("`{}`", tableAnnotation.name());
5454
} else {
55-
table = t.getClass().getName().toLowerCase();
55+
table = StrUtil.format("`{}`", t.getClass().getName().toLowerCase());
5656
}
5757

5858
// 获取所有字段,包含父类中的字段
@@ -89,7 +89,7 @@ public Integer insert(T t, Boolean ignoreNull) {
8989
// 构造值
9090
Object[] values = filterField.stream().map(field -> ReflectUtil.getFieldValue(t, field)).toArray();
9191

92-
String sql = StrUtil.format("INSERT INTO `{table}`({columns}) VALUES ({params})", Dict.create().set("table", table).set("columns", columns).set("params", params));
92+
String sql = StrUtil.format("INSERT INTO {table} ({columns}) VALUES ({params})", Dict.create().set("table", table).set("columns", columns).set("params", params));
9393
log.debug("【执行SQL】SQL:{}", sql);
9494
log.debug("【执行SQL】参数:{}", JSONUtil.toJsonStr(values));
9595
return jdbcTemplate.update(sql, values);

0 commit comments

Comments
 (0)