public static void main(String[] args) {
Environment environment = new Environment("mybatisFlex", new JdbcTransactionFactory(), new DelegatingDataSource());
FlexConfiguration configuration = new FlexConfiguration(environment);
FlexGlobalConfig globalConfig = FlexGlobalConfig.getDefaultConfig();
globalConfig.setConfiguration(configuration);
FlexGlobalConfig.setConfig("mybatisFlex", globalConfig, true);
configuration.addMapper(AccountMapper.class);
globalConfig.setDbType(DbType.MYSQL);
IAccountServiceImpl service = new IAccountServiceImpl();
AccountMapper baseMapper = Mappers.ofMapperClass(AccountMapper.class);
Field field = ReflectUtil.getField(ServiceImpl.class, "mapper");
ReflectUtil.setFieldValue(service, field, baseMapper);
System.out.println(service.updateChain()
.from(ACCOUNT)
.set(Account::getAge, 18)
.and(ACCOUNT.ID.ge(10)).toSQL());
}
正常输出构建的sql语句
java.lang.RuntimeException: Can not newInstance class: club.bigtian.study.domain.Account_$$_jvsta81_0
at com.mybatisflex.core.util.ClassUtil.newInstance(ClassUtil.java:168)
at com.mybatisflex.core.update.ModifyAttrsRecordProxyFactory.get(ModifyAttrsRecordProxyFactory.java:58)
at com.mybatisflex.core.util.UpdateEntity.of(UpdateEntity.java:35)
at com.mybatisflex.core.update.UpdateChain.createEntity(UpdateChain.java:84)
at com.mybatisflex.core.update.UpdateChain.(UpdateChain.java:68)
at com.mybatisflex.core.update.UpdateChain.create(UpdateChain.java:90)
at com.mybatisflex.core.service.IService.updateChain(IService.java:648)
at club.bigtian.study.service.impl.MybatisFlexSqlPreview.main(MybatisFlexSqlPreview.java:36)
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "com.mybatisflex.core.update.UpdateWrapper.set(com.mybatisflex.core.util.LambdaGetter, Object, boolean)" because "this.entityWrapper" is null
at com.mybatisflex.core.update.UpdateChain.set(UpdateChain.java:107)
at com.mybatisflex.core.update.UpdateChain.set(UpdateChain.java:39)
at com.mybatisflex.core.update.PropertySetter.set(PropertySetter.java:123)
at club.bigtian.study.service.impl.MybatisFlexSqlPreview.main(MybatisFlexSqlPreview.java:38)
Disconnected from the target VM, address: '127.0.0.1:54054', transport: 'socket'
1.7.5