fix SQLProvider.updateSelective update empty

This commit is contained in:
Timi
2026-01-04 12:11:24 +08:00
parent 1508bf7c7f
commit 4c1cdf0a91

View File

@ -278,7 +278,7 @@ public class SQLProvider {
}
String setClause = meta.fieldColumnList.stream()
.filter(FieldColumn::isNotId)
.filter(fc -> fc.isNotEmpty(entity))
.filter(fc -> fc.isNotNull(entity))
.map(fc -> "`%s` = #{%s}".formatted(fc.columnName, fc.fieldName))
.collect(Collectors.joining(", "));
return "UPDATE `%s` SET %s WHERE `%s` = #{%s}".formatted(meta.table, setClause, meta.idFieldColumn.columnName, meta.idFieldColumn.fieldName);
@ -551,6 +551,18 @@ public class SQLProvider {
}
}
public boolean isNull(Object entity) {
try {
return Ref.getFieldValue(entity, field, Object.class) == null;
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
public boolean isNotNull(Object entity) {
return !isNull(entity);
}
public boolean isEmpty(Object entity) {
try {
return TimiJava.isEmpty(Ref.getFieldValue(entity, field, Object.class));