mybatis 使用in 查询时报错_使用 Mybatis Plus 封装批量查询出错

在使用 Mybatis Plus 封装批量查询时遇到异常,问题源于`SqlSession`中尝试访问`EntityWrapper`的'ew'属性而找不到对应的getter方法。错误堆栈显示为`ReflectionException`,提示没有在`com.baomidou.mybatisplus.mapper.EntityWrapper`类中找到名为'ew'的getter方法。解决方案可能涉及到检查传入参数或`EntityWrapper`的使用方式。在Gitee仓库中发现类似问题,但具体情况不同。
摘要由CSDN通过智能技术生成

使用 Mybatis Plus 封装批量查询出错

环境

JDK 1.8

Spring Boot 2.0.6.RELEASE

mybatis-plus-boot-starter 2.3

场景

吾辈需要封装一个可以根据对象列表查询的通用方法,于是写了下面这样一个方法

注:这个类继承了 IServiceImpl

public List listBatchByEntityList(List entityList) {

try (final SqlSession batchSqlSession = sqlSessionBatch()) {

final int size = entityList.size();

final int batchSize = 30;

final List result = new ArrayList<>();

for (int i = 0; i < size; i++) {

final String sqlStatement = sqlStatement(SqlMethod.SELECT_LIST);

final List list = batchSqlSession.selectList(sqlStatement, new EntityWrapper<>(entityList.get(i)));

result.addAll(list);

if (i >= 1 && i % batchSize == 0) {

batchSqlSession.flushStatements();

}

}

batchSqlSession.flushStatements();

return result;

} catch (Exception e) {

throw new GlobalException("Error: Cannot execute listBatchByEntityList Method. Cause", e);

}

}

然而运行时发生了异常

Caused by: org.apache.ibatis.exceptions.PersistenceException:

### Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'ew' in 'class com.baomidou.mybatisplus.mapper.EntityWrapper'

### Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'ew' in 'class com.baomidou.mybatisplus.mapper.EntityWrapper'

at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)

at com.zx.idc.ds.common.service.impl.BaseServiceImpl.listBatchByEntityList(BaseServiceImpl.java:54)

... 37 more

Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'ew' in 'class com.baomidou.mybatisplus.mapper.EntityWrapper'

at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:419)

at org.apache.ibatis.reflection.MetaClass.getGetInvoker(MetaClass.java:164)

at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:162)

at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:49)

at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122)

at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextMap.get(DynamicContext.java:94)

at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextAccessor.getProperty(DynamicContext.java:108)

at org.apache.ibatis.ognl.OgnlRuntime.getProperty(OgnlRuntime.java:2685)

at org.apache.ibatis.ognl.ASTProperty.getValueBody(ASTProperty.java:114)

at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)

at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258)

at org.apache.ibatis.ognl.ASTNotEq.getValueBody(ASTNotEq.java:50)

at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)

at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258)

at org.apache.ibatis.ognl.ASTAnd.getValueBody(ASTAnd.java:61)

at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)

at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258)

at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:470)

at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:434)

at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:44)

at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:32)

at org.apache.ibatis.scripting.xmltags.IfSqlNode.apply(IfSqlNode.java:34)

at org.apache.ibatis.scripting.xmltags.ChooseSqlNode.apply(ChooseSqlNode.java:35)

at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:33)

at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:41)

at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:292)

at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:134)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)

... 39 more

有人遇到过这种情况么?

附:吾辈看得懂错误,但不知道为什么 Mybatis Plus 查询列表会去找实体包装类 EntityWrapper 的 ew,而且 Google 上吾辈没有找到什么有用的答案 https://www.google.com/search...

在 Gitee 仓库那里有人遇到了类似的问题 关于自定义全局注入,wrapper 作为参数如何操作。,但方式不同,吾辈这边根本没在 BaseDao 定义接口

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值