确认
当前程序版本
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的时候有
Comment From: zshnb
这个应该是mybatis本身的问题,建议sql中不要有超过1行的连续空行
Comment From: zt9788
这个应该是mybatis本身的问题,建议sql中不要有超过1行的连续空行
mp 3.5.7 同样的sql时没问题的,我看了一下mybatis版本是一样的
Comment From: good-and-more
你是否在xml文件中,把自己的sql注释了很多行?我也遇到了类似的问题,刚刚测试把注释的内容全删掉就不报错,把注释的内容留着就报错。mp 3.5.7
Comment From: zt9788
你是否在xml文件中,把自己的sql注释了很多行?我也遇到了类似的问题,刚刚测试把注释的内容全删掉就不报错,把注释的内容留着就报错。mp 3.5.7
确实注释不少,不过3.5.7没错,3.5.8就不行
Comment From: cnz19191
遇到了相似的问题,自定义的update sql语句注入器,批量更新的时候,提示有\n的语法错误。3.5.3
Comment From: nieqiurong