相关文章推荐
儒雅的炒饭  ·  script ...·  1 年前    · 
高大的荔枝  ·  c# - Dependency ...·  1 年前    · 

【Java异常】com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not use this method fo

No8g攻城狮

【Java异常】com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not use this method fo


本文目录

一、问题描述

二、问题原因

三、解决方案


项目背景描述: spring-boot (2.1.5) + mybatis-plus (3.3.1) + jdk8

一、问题描述

错误信息如下:

Caused by: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'ew != null and ew.sqlFirst != null'. Cause: org.apache.ibatis.ognl.OgnlException: sqlFirst

.......

Caused by: org.apache.ibatis.ognl.OgnlException: sqlFirst

........

Caused by: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not use this method for "getSqlFirst"

........

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.util.ArrayList.forEach(ArrayList.java:1249)
	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:297)
	at com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.query(MybatisCachingExecutor.java:88)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426)
	... 69 common frames omitted
Caused by: org.apache.ibatis.ognl.OgnlException: sqlFirst
	at org.apache.ibatis.ognl.OgnlRuntime.getMethodValue(OgnlRuntime.java:1693)
	at org.apache.ibatis.ognl.ObjectPropertyAccessor.getPossibleProperty(ObjectPropertyAccessor.java:60)
	at org.apache.ibatis.ognl.ObjectPropertyAccessor.getProperty(ObjectPropertyAccessor.java:147)
	at org.apache.ibatis.ognl.OgnlRuntime.getProperty(OgnlRuntime.java:2719)
	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.ASTChain.getValueBody(ASTChain.java:141)
	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:493)
	at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:457)
	at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:46)
	... 85 common frames omitted
Caused by: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not use this method for "getSqlFirst"
	at com.baomidou.mybatisplus.core.toolkit.ExceptionUtils.mpe(ExceptionUtils.java:49)
	at com.baomidou.mybatisplus.extension.conditions.AbstractChainWrapper.getSqlFirst(AbstractChainWrapper.java:272)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.apache.ibatis.ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:881)
	at org.apache.ibatis.ognl.OgnlRuntime.getMethodValue(OgnlRuntime.java:1691)
	... 103 common frames omitted

二、问题原因

是我在项目中使用了 mybatis-plus 里的 lambdaQuery() 表达式查询的原因,如下是一种错误写法。

public CommResponse<List<PushRuleResponse>> getByEventId(String devModel, String eventId) {
        List<MessageTemplateDO> messageTemplateDOS = messageTemplateMapper.selectList(lambdaQuery()
                .eq(MessageTemplateDO::getTemplateCode, request.getTemplateCode()));
        return CommResponse.ok(PushRuleConvert.INSTANCE.convertResponseList(list));
    }

三、解决方案

lambdaQuery() 表达式查询的方法改为 QueryWrapper() 条件构造器查询方法即可,如下图是正确的写法

private List<PushRuleDO> selectList(String devModel, String eventId){
        QueryWrapper<PushRuleDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dev_model", devModel);
        queryWrapper.eq("event_id", eventId);
        List<PushRuleDO> list = pushRuleMapper.selectList(queryWrapper);
        return list;
}

具体详细为什么 mybatis-plus 提供的这个方法不能用的原因还有待进一步查找。

完结!

上一篇: 【Java异常】com.netflix.hystrix.exception.HystrixRuntimeException: 类名#方法名failed and no fallback availabl

下一篇: 【工具使用】Intellij IDEA 自动清除无效 import 包 和 清除无效 import包 的快捷键

django.core.exceptions.ImproperlyConfigured:

django.core.exceptions.ImproperlyConfigured: WSGI application 'luffy_permission.wsgi.application' could not be loaded; Error importing module: 'No module named 'rbac.middlewares.rbac''django.core.exceptions.ImproperlyConfigured: WSGI application 'luffy_permission.wsgi.application' could not be loaded; Error importing module: 'No module named 'rbac.middlewares.rbac''django.core.exceptions.ImproperlyConfigured: WSGI application 'luffy_permission.wsgi.application' could not be loaded;

java集成开发环境哪个好 java 集成

java基础–继承、实现、依赖、关联、聚合、组合的联系与区别1.继承(is-a)指的是一个类或者接口继承另一个类或者接口,而且可以增加自己的新功能。2.实现指的是一个class类实现interface接口。3.依赖(use- a)简单说,就是一个类中的方法用到了另一个类。 一般依赖关系在java中提现为局部变量、方法的形参,或者对静态方法的调用。 是一种弱关系。例如人用笔写字,人与笔之间的关系就是