报错内容:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='dto.inDeptCode', mode=IN, javaType=class java.lang.Object, jdbcType=VARCHAR, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #5 with JdbcType VARCHAR . 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 #5 with JdbcType VARCHAR . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: 无效的列索引
原因:在这个sql语句里,if便签的前后我写了注释。在 MyBatis 的 XML 映射文件中,如果在 <if> 等动态标签前后添加注释,这些注释可能会被原样拼接到 SQL 语句中,破坏原有的语法结构(例如导致 WHERE 子句前后出现多余的 AND/OR 或括号不匹配),使得生成的 SQL 语句逻辑混乱甚至语法错误,进而导致数据库执行时无法正确解析查询条件,出现"无效索引"或直接报错;删除注释后,SQL 恢复为正确的动态拼接逻辑,问题即可解决。
解决:删除注释,重新运行,报错解决