springboot mybatis使用注解形式报错Could not set parameters for mapping: ParameterMapping{property='xxx'

末蓝、 2022-05-15 00:24 371阅读 0赞

如果你使用的是xml文件配置mapper,并且传入了null值,则也会引发这个错误:

Exception in thread “main” org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property=’dictionaryFilename’, mode=IN, javaType=class java.lang.String, 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: java.sql.SQLException: 无效的列索引

解决方法:根据网上资料说,是加上jdbcType,如

  1. #{dictionaryFilename,jdbcType = VARCHAR}

但是注解形式不是这个问题,因为#起的是一个占位符作用,而在java中字符串中$才能起到占位符作用,所以我们要将#变为$。

70

变为

70 1

这样解决了。

另外如果你要传入多个参数的时候,要么使用map传入,要么加上@Param注解

参考博客:https://blog.csdn.net/csdn_am/article/details/79854107

发表评论

表情:
评论列表 (有 0 条评论,371人围观)

还没有评论,来说两句吧...

相关阅读