From 621f151aa50ddb014b3cc04e3fb0c606103d12af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Sun, 30 Jul 2023 09:37:38 +0800 Subject: [PATCH] fixed: UpdateChain.toSQL() --- .../java/com/mybatisflex/core/table/TableInfo.java | 8 +++++--- .../com/mybatisflex/core/update/UpdateChain.java | 14 ++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java index 7ad205ae..07ff2b66 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java @@ -628,9 +628,11 @@ public class TableInfo { if (value != null) { ColumnInfo columnInfo = columnInfoMapping.get(column); - TypeHandler typeHandler = columnInfo.buildTypeHandler(); - if (typeHandler != null) { - value = new TypeHandlerObject(typeHandler, value, columnInfo.getJdbcType()); + if (columnInfo != null) { + TypeHandler typeHandler = columnInfo.buildTypeHandler(); + if (typeHandler != null) { + value = new TypeHandlerObject(typeHandler, value, columnInfo.getJdbcType()); + } } } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/UpdateChain.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/UpdateChain.java index efaf64e4..8e756aae 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/UpdateChain.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/update/UpdateChain.java @@ -25,10 +25,7 @@ import com.mybatisflex.core.query.QueryColumn; import com.mybatisflex.core.query.QueryWrapperAdapter; import com.mybatisflex.core.table.TableInfo; import com.mybatisflex.core.table.TableInfoFactory; -import com.mybatisflex.core.util.ClassUtil; -import com.mybatisflex.core.util.LambdaGetter; -import com.mybatisflex.core.util.SqlUtil; -import com.mybatisflex.core.util.UpdateEntity; +import com.mybatisflex.core.util.*; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -124,6 +121,7 @@ public class UpdateChain extends QueryWrapperAdapter> { return SqlUtil.toBool(baseMapper.deleteByQuery(this)); } + public boolean update() { return SqlUtil.toBool(baseMapper.updateByQuery(entity, this)); } @@ -133,8 +131,12 @@ public class UpdateChain extends QueryWrapperAdapter> { public String toSQL() { TableInfo tableInfo = TableInfoFactory.ofMapperClass(baseMapper.getClass()); CPI.setFromIfNecessary(this, tableInfo.getSchema(), tableInfo.getTableName()); - String sql = DialectFactory.getDialect().forUpdateEntityByQuery(tableInfo,entity,true,this); - return SqlUtil.replaceSqlParams(sql, CPI.getValueArray(this)); + String sql = DialectFactory.getDialect().forUpdateEntityByQuery(tableInfo, entity, true, this); + + Object[] values = tableInfo.buildUpdateSqlArgs(entity, true, true); + values = ArrayUtil.concat(values, CPI.getValueArray(this)); + + return SqlUtil.replaceSqlParams(sql, values); } }