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中包含多个\n可能解析失败 #6502

Closed
3 tasks done
zt9788 opened this issue Sep 20, 2024 · 6 comments
Closed
3 tasks done

[错误报告]: 当sql中包含多个\n可能解析失败 #6502

zt9788 opened this issue Sep 20, 2024 · 6 comments

Comments

@zt9788
Copy link

zt9788 commented Sep 20, 2024

确认

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

当前程序版本

3.5.8

问题描述

当sql中有多个\n的时候,报错

    @Select("""
    <script>
    select * from goods p
    where 1=1   and p.status = 1
    
    
    
    
    
    <if test='query.type != null'>
        AND p.type = #{query.type}
      
    </if>
    
    
    
    
    
    
    order by id desc 
    </script>
    """)
    Page<Goods> selectPage2(Page page,@Param("query") Goods query);

调用

Page<Goods> page = new Page<>();
page.setSize(10);
Goods goods = new Goods();
goods.setType(21);
var t2 = testMpMapper.selectPage2(page,goods);

详细堆栈日志

### Error querying database.  Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='query.type', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
### The error occurred while setting parameters
### SQL: SELECT COUNT(*) AS total FROM goods p WHERE 1 = 1 AND p.status = 1
### Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='query.type', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).


java.util.concurrent.ExecutionException: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "\n\n\n" <ST_SEMICOLON>

补充一下

3.5.7 没有这个问题
单独是用selectList 也没有这个问题,只有Page的时候有

@zshnb
Copy link

zshnb commented Sep 24, 2024

这个应该是mybatis本身的问题,建议sql中不要有超过1行的连续空行

@zt9788
Copy link
Author

zt9788 commented Sep 24, 2024

这个应该是mybatis本身的问题,建议sql中不要有超过1行的连续空行

mp 3.5.7 同样的sql时没问题的,我看了一下mybatis版本是一样的

@good-and-more
Copy link

你是否在xml文件中,把自己的sql注释了很多行?我也遇到了类似的问题,刚刚测试把注释的内容全删掉就不报错,把注释的内容留着就报错。mp 3.5.7

@zt9788
Copy link
Author

zt9788 commented Sep 26, 2024

你是否在xml文件中,把自己的sql注释了很多行?我也遇到了类似的问题,刚刚测试把注释的内容全删掉就不报错,把注释的内容留着就报错。mp 3.5.7

确实注释不少,不过3.5.7没错,3.5.8就不行

@cnz19191
Copy link

遇到了相似的问题,自定义的update sql语句注入器,批量更新的时候,提示有\n的语法错误。3.5.3

@nieqiurong
Copy link
Contributor

#6187

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

No branches or pull requests

5 participants