mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-06 16:48: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);
|
||||
|
||||
FlexAssert.notNull(entity, "entity can not be null");
|
||||
|
||||
Class<?> entityClass = entity.getClass();
|
||||
//如果是代理mybatis代理对象
|
||||
if(entity instanceof ProxyObject){
|
||||
entityClass = entityClass.getSuperclass();
|
||||
}
|
||||
// 该 Mapper 是通用 Mapper 无法通过 ProviderContext 获取,直接使用 TableInfoFactory
|
||||
TableInfo tableInfo = TableInfoFactory.ofEntityClass(ClassUtil.getUsefulClass(entity.getClass()));
|
||||
TableInfo tableInfo = TableInfoFactory.ofEntityClass(entityClass);
|
||||
|
||||
// 执行 onUpdate 监听器
|
||||
tableInfo.invokeOnUpdateListener(entity);
|
||||
|
||||
@ -82,19 +82,28 @@ public class DbTest {
|
||||
Map map2 = Db.selectFirstAndSecondColumnsAsMap("select * from tb_account");
|
||||
System.out.println(map);
|
||||
System.out.println(map2);
|
||||
assert map.equals(map2);
|
||||
|
||||
}
|
||||
@Test
|
||||
public void test03() {
|
||||
Account account = UpdateEntity.of(Account.class,1);
|
||||
account.setAge(1);
|
||||
List<Account> accounts = new ArrayList<>();
|
||||
accounts.add(account);
|
||||
Account account2 = UpdateEntity.of(Account.class,2);
|
||||
account2.setAge(2);
|
||||
UpdateWrapper updateWrapper = UpdateWrapper.of(account2);
|
||||
updateWrapper.setRaw("age","age+1");
|
||||
accounts.add(account2);
|
||||
Db.updateEntitiesBatch(accounts);
|
||||
try {
|
||||
Account account = UpdateEntity.of(Account.class, 1);
|
||||
account.setAge(1);
|
||||
List<Account> accounts = new ArrayList<>();
|
||||
accounts.add(account);
|
||||
Account account2 = UpdateEntity.of(Account.class, 2);
|
||||
account2.setAge(2);
|
||||
UpdateWrapper updateWrapper = UpdateWrapper.of(account2);
|
||||
updateWrapper.setRaw("age", "age+1");
|
||||
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