mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
fix Db.updateEntitiesBatch更新部分字段时报错的问题
This commit is contained in:
parent
2d9d05b6e5
commit
434b948b8a
@ -245,9 +245,13 @@ public class RowSqlProvider {
|
|||||||
Object entity = ProviderUtil.getEntity(params);
|
Object entity = ProviderUtil.getEntity(params);
|
||||||
|
|
||||||
FlexAssert.notNull(entity, "entity can not be null");
|
FlexAssert.notNull(entity, "entity can not be null");
|
||||||
|
Class<?> entityClass = entity.getClass();
|
||||||
|
//如果是代理mybatis代理对象
|
||||||
|
if(entity instanceof ProxyObject){
|
||||||
|
entityClass = entityClass.getSuperclass();
|
||||||
|
}
|
||||||
// 该 Mapper 是通用 Mapper 无法通过 ProviderContext 获取,直接使用 TableInfoFactory
|
// 该 Mapper 是通用 Mapper 无法通过 ProviderContext 获取,直接使用 TableInfoFactory
|
||||||
TableInfo tableInfo = TableInfoFactory.ofEntityClass(ClassUtil.getUsefulClass(entity.getClass()));
|
TableInfo tableInfo = TableInfoFactory.ofEntityClass(entityClass);
|
||||||
|
|
||||||
// 执行 onUpdate 监听器
|
// 执行 onUpdate 监听器
|
||||||
tableInfo.invokeOnUpdateListener(entity);
|
tableInfo.invokeOnUpdateListener(entity);
|
||||||
|
|||||||
@ -82,19 +82,28 @@ public class DbTest {
|
|||||||
Map map2 = Db.selectFirstAndSecondColumnsAsMap("select * from tb_account");
|
Map map2 = Db.selectFirstAndSecondColumnsAsMap("select * from tb_account");
|
||||||
System.out.println(map);
|
System.out.println(map);
|
||||||
System.out.println(map2);
|
System.out.println(map2);
|
||||||
|
assert map.equals(map2);
|
||||||
|
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void test03() {
|
public void test03() {
|
||||||
Account account = UpdateEntity.of(Account.class,1);
|
try {
|
||||||
account.setAge(1);
|
Account account = UpdateEntity.of(Account.class, 1);
|
||||||
List<Account> accounts = new ArrayList<>();
|
account.setAge(1);
|
||||||
accounts.add(account);
|
List<Account> accounts = new ArrayList<>();
|
||||||
Account account2 = UpdateEntity.of(Account.class,2);
|
accounts.add(account);
|
||||||
account2.setAge(2);
|
Account account2 = UpdateEntity.of(Account.class, 2);
|
||||||
UpdateWrapper updateWrapper = UpdateWrapper.of(account2);
|
account2.setAge(2);
|
||||||
updateWrapper.setRaw("age","age+1");
|
UpdateWrapper updateWrapper = UpdateWrapper.of(account2);
|
||||||
accounts.add(account2);
|
updateWrapper.setRaw("age", "age+1");
|
||||||
Db.updateEntitiesBatch(accounts);
|
accounts.add(account2);
|
||||||
|
Account account3 = new Account();
|
||||||
|
account3.setId(3L);
|
||||||
|
account3.setAge(4);
|
||||||
|
accounts.add(account3);
|
||||||
|
Db.updateEntitiesBatch(accounts);
|
||||||
|
}catch (Exception e){
|
||||||
|
assert false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user