Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[错误报告]: 标签前后的静态sql的换行符没了,标签前后的两行被合并到了一行,导致执行报错 #6704

Open
3 tasks done
IMMOLK opened this issue Feb 13, 2025 · 5 comments

Comments

@IMMOLK
Copy link

IMMOLK commented Feb 13, 2025

确认

  • 我使用的版本是最新版, 并且使用插件确认过项目里无依赖版本冲突
  • 我已经在 issue 中搜索过, 确认问题没有被提出过
  • 我已经修改标题, 将标题中的 描述 替换为遇到的问题

当前程序版本

3.5.10.1

问题描述

标签前后的静态sql的换行符没了,标签前后的两行被合并到了一行。
比如xml中sql如下

        select 1 from table s
        where s.field1 > 0 --注释
        <if test="id == 3">
            and s.field2 = #{id}
        </if>
        and #{field3} > 0

条件A不满足时,最后的sql合并成了两行

select 1 from table s
        where s.field1 > 0 --注释 and #{field3} > 0

后面的and #{field3} > 0也被当成了注释,但是生成的预编译绑定参数又会多一个#{filed3},导致绑定参数时就因为索引溢出报错了

详细堆栈日志

@IMMOLK IMMOLK changed the title [错误报告]: 描述 [错误报告]: 标签前后的静态sql的换行符没了,标签前后的两行被合并到了一行,导致执行报错 Feb 13, 2025
@miemieYaho
Copy link
Member

mybatis/mybatis-3#3349 和这个有关吧,建议你换个方式写注释比如原生xml支持的注释格式

@IMMOLK
Copy link
Author

IMMOLK commented Feb 13, 2025

mybatis/mybatis-3#3349 和这个有关吧,建议你换个方式写注释比如原生xml支持的注释格式

我看了下代码和提交记录,解析xml去除换行符是mybatis-plus实现的,https://github.com/baomidou/mybatis-plus/issues/6187,这个去除换行符的功能是否可以根据配置决定呢

@miemieYaho
Copy link
Member

那你debug看CCJSqlParserUtil.sanitizeSingleSql用了吗?

@IMMOLK
Copy link
Author

IMMOLK commented Feb 13, 2025

那你debug看CCJSqlParserUtil.sanitizeSingleSql用了吗?

执行mapper的查询方法,没有看到调用这个,这个方法会在什么情况下调用吗

@miemieYaho
Copy link
Member

没地方调用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants