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

mybatis报错:optimize this sql to a count sql has exception:…………………… exception:
null 我的sql语句是这样的:

    <select id="getAllProjects" resultType="*******">
        (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} )
    </select>

mybatis-plus的版本是4.0以上的,在网上看了博客报错的都是3.4,3.5;

image.png
该mapper方法的形参是这样的,ew是我的一个queryWrapper。

阅读 2.7k
1 个回答

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题