当前使用版本(必填,否则不予处理)
3.4.1 尝试过低版本也不可以正常使用
该问题是如何引起的?(确定最新版也有问题再提!!!)
使用最新版调用自带的lambdaQuery()查询异常
重现步骤(如果有就写完整)
调用代码 hpcInfoService实现类中的代码,该类声明
public class HpcInfoServiceImpl extends ServiceImpl<HpcInfoMapper, HpcInfo>
implements IHpcInfoService {
接口声明
public interface IHpcInfoService extends IService<HpcInfo>
@Override
public List<HpcInfo> listHpcByClusters(List<String> clusterIds) {
return list(lambdaQuery().in(HpcInfo::getClusterId, clusterIds));
}
@Override
public List<HpcInfo> listHpcIn1(String clusterId) {
return list(lambdaQuery().in(HpcInfo::getClusterId, clusterId));
}
@Override
public List<HpcInfo> listHpcByEq(String clusterId) {
return list(lambdaQuery().eq(HpcInfo::getClusterId, clusterId));
}
测试代码
@Test
public void hpcListCache() {
// 使用new QueryWrapper<HpcInfo>().lambda().in传入List IN,正常可用
hpcInfoService
.list(new QueryWrapper<HpcInfo>().lambda().in(HpcInfo::getClusterId, List.of("1")))
.forEach(System.out::println);
// 使用lambdaQuery().eq(HpcInfo::getClusterId, clusterId) 传入单独的一个字符 EQ ,异常不可用
hpcInfoService.listHpcByEq("1").forEach(System.out::println);
// 使用lambdaQuery().in(HpcInfo::getClusterId, clusterId) 传入单独的一个字符 IN,异常不可用
hpcInfoService.listHpcIn1("1").forEach(System.out::println);
// lambdaQuery().in(HpcInfo::getClusterId, clusterIds) 传入List IN,异常不可用
hpcInfoService.listHpcByClusters(List.of("1")).forEach(System.out::println);
}
控制台执行日志,只有第一个使用new QueryWrapper
报错信息
Caused by: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'ew != null and ew.sqlFirst != null'. Cause: org.apache.ibatis.ognl.OgnlException: sqlFirst [com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not use this method for "getSqlFirst"]
at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:48)
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.lambda$apply$0(MixedSqlNode.java:32)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:32)
at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:39)
at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:305)
at com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.query(MybatisCachingExecutor.java:90)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426)
Comment From: YAGAMIL
补充:使用Wrappers构造lambdaQuery可以正常使用,
// 使用Wrappers.<HpcInfo>lambdaUpdate() 传入List IN
hpcInfoService
.list(Wrappers.<HpcInfo>lambdaUpdate().in(HpcInfo::getClusterId, List.of("1")))
.forEach(System.out::println);
执行正常,我不知道为什么IService
Comment From: miemieYaho
看源码注释
Comment From: guajiguaji-dd
补充:使用Wrappers构造lambdaQuery可以正常使用,
// 使用Wrappers.<HpcInfo>lambdaUpdate() 传入List IN hpcInfoService .list(Wrappers.<HpcInfo>lambdaUpdate().in(HpcInfo::getClusterId, List.of("1"))) .forEach(System.out::println);执行正常,我不知道为什么IService中的lambadQuery()我是否有合理使用,如果我错了那它的使用方式是怎么样的,如果该方法不可以正常使用,那么引入该方法的意义是什么,在哪里用到它,求告知,万分感谢
LambdaQueryChainWrapper.one()
e.g. lambdaQuery().eq(col, val).one()
Comment From: Rainsheep
mark
Comment From: Rainsheep
lambdaQuery() 正确用法
List