我的代码:
@Select("SELECT * FROM book_info LEFT JOIN book_type ON book_info.book_type=book_type.id ${ew.customSqlSegment}")
IPage<BookInfoVo> queryAll(Page<BookInfoVo> page, @Param("ew") QueryWrapper<BookInfo> queryWrapper);
报错信息如下:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression ‘ew.customSqlSegment’. Cause: org.apache.ibatis.ognl.NoSuchPropertyException: com.baomidou.mybatisplus.core.conditions.query.QueryWrapper.customSqlSegment
原因:Mybatis Plus 3.0.7 版本才开始用【自定义sql】+【QueryWrapper】。
换成3.0.7版本之后来了个新错:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: Error instantiating interface com.baomidou.mybatisplus.core.metadata.IPage with invalid types () or values (). Cause: java.lang.NoSuchMethodException: com.baomidou.mybatisplus.core.metadata.IPage.()
原因:多次测试发现可以返回List不能返回IPage,不然就会报错。最后将Mybatis Plus 版本设置成3.2.0,完美解决。
Mybatis-Plus 3.2.0:
移除 PerformanceInterceptor 相关(SQL执行效率插件), 建议使用 p6spy(p6spy是一个开源项目,通常使用它来跟踪数据库操作,查看程序运行过程中执行的sql语句。)
参考:
补充一个错误
Resolved [org.mybatis.spring.MyBatisSystemException: nested exception
is org.apache.ibatis.exceptions.TooManyResultsException: Expected one
result (or null) to be returned by selectOne(), but found: 6]
mybatis-plus 中page参数不在第一个位置,返回的结果集接收对象不被认为是一个集合,而放在第一位就没有问题。
https://blog.youkuaiyun.com/weixin_43611145/article/details/106501748