当前位置: 首页 > 知识库问答 >
问题:

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

马高谊
2024-01-29

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;

共有1个答案

邓正真
2024-01-29

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

 类似资料:
  • Mybatis-Plus 是一个 MyBatis 增强工具包,简化 CRUD 操作。 启动加载 XML 配置时注入单表 SQL 操作 ,为简化开发工作、提高生产率而生。 Maven 坐标 http://search.maven.org/#search%7Cga%7C1%7Cmybatis-plus     com.baomidou    mybatis-plus    maven 官方最新版本号为

  • 今天在写demo的是有使用Assert.asserEquals(3,result);一直报错 按道理我已经引入断言对象,但还是报错 Junit5.4 版本不支持这样写吗? 有没有大佬知道呢?

  •   mybatis分页插件MicroPageInterceptor 特点: 1, 支持mysql和oracle分页 2, 不必在xml编写统计count的sql 3, 使用RowBounds子类PageInfo作为分页信息和记录总数的载体,不必像其他分页插件那样要求输入输出参数必须继承特殊父类。 4, 可在PageInfo中填写自定义排序sql串,提高查询性能和排序灵活性   jar已经提交mav

  • 1.介绍: MyBatis generator plus 基于mybatis-generator-core v.1.3.2 扩展,增加如下主要特性: 1.生成支持Oracle、Mysql、Sqlserver分页查询的代码: //分页查询demoOperateLogExample relationshipsExample = new OperateLogExample();relationships

  • 两个类,User中包含order 其中mapper和mapper.xml均用mybatis-plus自动生成 UserMapper UserMapperImpl OrderMapper OrderMapperImpl 测试 报错如下 这种报错是什么造成的呢?如何破

  • 1. 前言 在spring-boot 集成 MyBatis小节中,我们介绍了如何在 spring-boot 中集成 MyBatis,MyBatis 虽然灵活,但是对于业务开发还略显不够。MyBatis-Plus 是国内开发者为 MyBatis 定制的一款增强工具,在不侵入 MyBatis 的基础上能够快速地提升 MyBatis 的开发能力,为开发者节省大量的时间。 提示: 本小节建立在spring