mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
fix: UpdateEntity 没有对 @Column(ignore = true) 的字段进行过滤 close #I7RE0J
This commit is contained in:
parent
d4163a2f0f
commit
f23cf43a45
@ -748,11 +748,11 @@ public class CommonsDialectImpl implements IDialect {
|
|||||||
|
|
||||||
StringJoiner stringJoiner = new StringJoiner(DELIMITER);
|
StringJoiner stringJoiner = new StringJoiner(DELIMITER);
|
||||||
|
|
||||||
for (String modifyAttr : updateColumns) {
|
for (String updateColumn : updateColumns) {
|
||||||
if (rawValueMap.containsKey(modifyAttr)) {
|
if (rawValueMap.containsKey(updateColumn)) {
|
||||||
stringJoiner.add(wrap(modifyAttr) + EQUALS + rawValueMap.get(modifyAttr).toSql(this));
|
stringJoiner.add(wrap(updateColumn) + EQUALS + rawValueMap.get(updateColumn).toSql(this));
|
||||||
} else {
|
} else {
|
||||||
stringJoiner.add(wrap(modifyAttr) + EQUALS_PLACEHOLDER);
|
stringJoiner.add(wrap(updateColumn) + EQUALS_PLACEHOLDER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -362,7 +362,7 @@ public class TableInfo {
|
|||||||
for (int i = 0; i < columnInfoList.size(); i++) {
|
for (int i = 0; i < columnInfoList.size(); i++) {
|
||||||
ColumnInfo columnInfo = columnInfoList.get(i);
|
ColumnInfo columnInfo = columnInfoList.get(i);
|
||||||
//真正的字段(没有做忽略标识)
|
//真正的字段(没有做忽略标识)
|
||||||
if (!columnInfo.isIgnore()){
|
if (!columnInfo.isIgnore()) {
|
||||||
columnNames.add(columnInfo.column);
|
columnNames.add(columnInfo.column);
|
||||||
|
|
||||||
columnInfoMapping.put(columnInfo.column, columnInfo);
|
columnInfoMapping.put(columnInfo.column, columnInfo);
|
||||||
@ -521,6 +521,7 @@ public class TableInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public Map<String, RawValue> obtainUpdateRawValueMap(Object entity) {
|
public Map<String, RawValue> obtainUpdateRawValueMap(Object entity) {
|
||||||
if (!(entity instanceof UpdateWrapper)) {
|
if (!(entity instanceof UpdateWrapper)) {
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
@ -557,7 +558,13 @@ public class TableInfo {
|
|||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
for (String property : updates.keySet()) {
|
for (String property : updates.keySet()) {
|
||||||
String column = getColumnByProperty(property);
|
// String column = getColumnByProperty(property);
|
||||||
|
String column = propertyColumnMapping.get(property);
|
||||||
|
if (column == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (onUpdateColumns != null && onUpdateColumns.containsKey(column)) {
|
if (onUpdateColumns != null && onUpdateColumns.containsKey(column)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -628,12 +635,14 @@ public class TableInfo {
|
|||||||
if (updates.isEmpty()) {
|
if (updates.isEmpty()) {
|
||||||
return FlexConsts.EMPTY_ARRAY;
|
return FlexConsts.EMPTY_ARRAY;
|
||||||
}
|
}
|
||||||
// Set<String> properties = (Set<String>) updates;
|
|
||||||
// if (properties.isEmpty()) {
|
|
||||||
// return values.toArray();
|
|
||||||
// }
|
|
||||||
for (String property : updates.keySet()) {
|
for (String property : updates.keySet()) {
|
||||||
String column = getColumnByProperty(property);
|
|
||||||
|
String column = propertyColumnMapping.get(property);
|
||||||
|
if (column == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (onUpdateColumns != null && onUpdateColumns.containsKey(column)) {
|
if (onUpdateColumns != null && onUpdateColumns.containsKey(column)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -718,6 +727,7 @@ public class TableInfo {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取主键值
|
* 获取主键值
|
||||||
|
*
|
||||||
* @param entity
|
* @param entity
|
||||||
* @return 主键值,有多个主键时返回数组
|
* @return 主键值,有多个主键时返回数组
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -157,6 +157,23 @@ public class AccountTester {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* issues https://gitee.com/mybatis-flex/mybatis-flex/issues/I7RE0J
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testUpdateByUpdateWrapper() {
|
||||||
|
Account account = new Account();
|
||||||
|
account.setId(1L);
|
||||||
|
account = UpdateWrapper.of(account)
|
||||||
|
.set(Account::getId,1)
|
||||||
|
.set(Account::getAge, 20)
|
||||||
|
//设置 Ignore 字段,会被自动忽略
|
||||||
|
.setRaw(Account::getTitle, "xxxx")
|
||||||
|
.toEntity();
|
||||||
|
accountMapper.update(account);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user