学无先后,达者为师

网站首页 编程语言 正文

Mybatis传入参数类型不匹配导致的报错:

作者:小哥骑单车 更新时间: 2022-11-29 编程语言

1、先来看错误异常:

com.cfc.common.utils.TranFailException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'bussNo' in 'class java.lang.String'-->nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'bussNo' in 'class java.lang.String'
    at com.cfc.common.utils.LogUtil$HanderExVo.invoke(LogUtil.java:412)
    at com.cfc.common.utils.LogUtil.handerEx(LogUtil.java:319)
    at com.cfc.common.utils.LogUtil.handerEx(LogUtil.java:280)
    at com.cfc.common.utils.LogUtil.handerEx(LogUtil.java:257)
    at com.cfc.common.utils.LogUtil.handerEx(LogUtil.java:245)

2、代码实现:

对应的java中,是string类型:

 

然后mybatis的xml中,是map类型:

 

3、报错的地方:

然后mybatis的xml中执行的代码:

 

 

 如果不更改java代码中String->Map类型,

我发现去掉if  test 标签,也可以正常执行:

4、当然,正确的修改方式,还是要把传参类型匹配对应上:

 

或者在mybatis中,修改对应的

parameterType="map" 

parameterType="java.lang.String"

至于原理,要去看mybatis里面的反射源码了:

 org.apache.ibatis.reflection.Reflector

 

这里也是由于不小心犯了一个低级错误: 

 

原文链接:https://blog.csdn.net/lejustdoit/article/details/120156769

栏目分类
最近更新