Mybatis Plus 自定义sql + QueryWrapper

我的代码:

@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语句。)

参考:

发布了3 篇原创文章 · 获赞 4 · 访问量 106

猜你喜欢

转载自blog.csdn.net/weixin_44188501/article/details/104317333