发现了Mybatis一个很不直观的错误,从字面上根本看不出哪里有问题
异常详情:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'ew.sqlSegment != null and ew.sqlSegment != '' and ew.nonEmptyOfWhere'. Cause: org.apache.ibatis.ognl.OgnlException: sqlSegment [java.lang.NullPointerException]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)
at com.sun.proxy.$Proxy180.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:173)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:78)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148)
只能看出是空指针,于是我用断点跟踪我传的查询条件,发现全部都有值。
结果万万没想到是字段不存在导致的...........
请看我的查询条件怎么写的
这个字段点进去
注意!!!问题来了 !!!
可以看到这是一个虚拟字段,并不存在于表中,用它来做条件肯定有问题。
于是把这个条件去掉之后,顺利解决问题。
真得吐槽一下,mybatis就不能把这个错报成 column 'xxx' is not exist 吗。