mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
!404 fix Db.updateEntitiesBatch更新部分字段时报错的问题
Merge pull request !404 from tangxin/main
This commit is contained in:
commit
b2f701d7bb
@ -247,8 +247,8 @@ public class RowSqlProvider {
|
|||||||
FlexAssert.notNull(entity, "entity can not be null");
|
FlexAssert.notNull(entity, "entity can not be null");
|
||||||
|
|
||||||
// 该 Mapper 是通用 Mapper 无法通过 ProviderContext 获取,直接使用 TableInfoFactory
|
// 该 Mapper 是通用 Mapper 无法通过 ProviderContext 获取,直接使用 TableInfoFactory
|
||||||
TableInfo tableInfo = TableInfoFactory.ofEntityClass(ClassUtil.getUsefulClass(entity.getClass()));
|
|
||||||
|
|
||||||
|
TableInfo tableInfo = TableInfoFactory.ofEntityClass(ClassUtil.getUsefulClass(entity.getClass()));
|
||||||
// 执行 onUpdate 监听器
|
// 执行 onUpdate 监听器
|
||||||
tableInfo.invokeOnUpdateListener(entity);
|
tableInfo.invokeOnUpdateListener(entity);
|
||||||
|
|
||||||
|
|||||||
@ -70,14 +70,15 @@ public class ClassUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T> Class<T> getUsefulClass(Class<T> clazz) {
|
public static <T> Class<T> getUsefulClass(Class<T> clazz) {
|
||||||
|
|
||||||
|
if (ProxyObject.class.isAssignableFrom(clazz)) {
|
||||||
|
return (Class<T>) clazz.getSuperclass();
|
||||||
|
}
|
||||||
|
|
||||||
if (isProxy(clazz)) {
|
if (isProxy(clazz)) {
|
||||||
return getJdkProxySuperClass(clazz);
|
return getJdkProxySuperClass(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (ProxyObject.class.isAssignableFrom(clazz)){
|
|
||||||
// return (Class<T>) clazz.getSuperclass();
|
|
||||||
// }
|
|
||||||
|
|
||||||
//ControllerTest$ServiceTest$$EnhancerByGuice$$40471411#hello -------> Guice
|
//ControllerTest$ServiceTest$$EnhancerByGuice$$40471411#hello -------> Guice
|
||||||
//com.demo.blog.Blog$$EnhancerByCGLIB$$69a17158 ----> CGLIB
|
//com.demo.blog.Blog$$EnhancerByCGLIB$$69a17158 ----> CGLIB
|
||||||
//io.jboot.test.app.TestAppListener_$$_jvstb9f_0 ------> javassist
|
//io.jboot.test.app.TestAppListener_$$_jvstb9f_0 ------> javassist
|
||||||
|
|||||||
@ -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