Spring Boot& Mybatis关于解决TypeException: Could not set parameters for mapping的办法

首先来写下我先在遇到的问题:

Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='pkEmailInfoId', mode=IN, javaType=long, 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: Parameter index out of range (1 > number of parameters, which is 0).
### The error may involve com.scut.emos.dao.MailMapper.createInfo-Inline
### The error occurred while setting parameters
### SQL: `       INSERT INTO tb_email_info (pk_email_info_id, project_id, email_name, email_address, password, auth_code, protocol, server_host, create_time)         VALUES (?, ?, ?,?, ?, ?, ?, ?, ?)
### Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='pkEmailInfoId', mode=IN, javaType=long, 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: Parameter index out of range (1 > number of parameters, which is 0).
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:57)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
	at com.sun.proxy.$Proxy146.createInfo(Unknown Source)
	... 96 more
Caused by: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='pkEmailInfoId', mode=IN, javaType=long, 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: Parameter index out of range (1 > number of parameters, which is 0).

但是前面我在程序中利用System.out.println()输出发现

在我传入的对象中,是有数据存在的,那么现在问题出自什么地方呢?

但是后来我上网查的说什么是因为xml文件里面有注释的,但是我的xml文件里面并没有任何的注释啊?

我也尝试过在xml的文件里面添加jdbcType,如:

VALUES (#{pkEmailInfoId,jdbcType=BIGINT})

(这里有个需要注意的地方,就是如果jdbcType指定的类型不是jdbc的类型的话,在运行的时候回直接退出,Process finished with exit code 0, 没有任何报错,如果你们在开发过程中遇到这个问题的话,不妨考虑一下是不是mapper中出现了问题)

最后,我在mapper.java的接口文件中,我把映射函数的返回类型把void改成了int,运行成功了???

修改前:

void createInfo(MailClass mailClass);

修改后:

 int createInfo(MailClass mailClass);

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值