Mybatis-Plus报错optimize this sql to a count sql has exception是为什么?-灵析社区

一只臭美的Doggg

mybatis报错:optimize this sql to a count sql has exception:…………………… exception: null 我的sql语句是这样的: (select distinct projects.*,unitUser.uname as unitName,adminUser.uname as userName from projects inner join unitUser on projects.unitId=unituser.id inner join adminProject on adminProject.projectId = projects.id inner join adminUser on adminUser.id = adminproject.userId ${ew.customSqlSegment} ) UNION (select distinct projects.*,unitUser.uname as unitName,null as userName from projects inner join unitUser on projects.unitId=unituser.id and projects.id not in ( select projects.id from projects inner join adminProject on adminProject.projectId = projects.id ) ${ew.customSqlSegment} ) mybatis-plus的版本是4.0以上的,在网上看了博客报错的都是3.4,3.5; ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241012/15b5e52e0777d5ee27ddd5eb7fe72dd4.png) 该mapper方法的形参是这样的,ew是我的一个queryWrapper。

阅读量:119

点赞量:0

问AI
报错提示是SOL的解析异常: ${} 解析为SQL时,将形参变量的值直接取出,直接拼接显示在SQL中, "${ew.customSqlSegment}"需要加引号: "'${ew.customSqlSegment}'" , 题干中没有说形参变量结构那么猜测"${ew.customSqlSegment}"这个可能应该这样: "${customSqlSegment}", 并且出于安全与性能考虑,不建议使用"${}", 而是使用"#{}", "#{}"不用加引号