報錯如下:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'ew != null and ew.sqlSelect != null'. Cause: org.apache.ibatis.ognl.OgnlException: sqlSelect [com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not use this method for "getSqlSelect"]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy185.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:177)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:78)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:96)
at com.sun.proxy.$Proxy189.selectList(Unknown Source)
at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.list(ServiceImpl.java:284)
原因:
使用了錯誤的寫法
LambdaQueryChainWrapper<User> chainWrapper = lambdaQuery();
List<User> userList = this.list(chainWrapper);
大概原因是: LambdaQueryChainWrapper 其實并不應(yīng)該被用做一個傳遞給list方法的wrapper參數(shù)发钝,因為它本身就有query的功能锋谐。所以我們使用它來作為描述參數(shù)的時候就報錯了录淡!更詳細(xì)的邏輯請自行查看源碼.
解決:
LambdaQueryChainWrapper<User> chainWrapper = lambdaQuery();
List<User> userList = chainWrapper.list();
或者
LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
List<User> userList = this.list(lambdaQueryWrapper);