Mybatis异常There is no getter for property named 'XXX' in 'class java.lang.String'(示例代

Posted 火之非常高兴

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mybatis异常There is no getter for property named 'XXX' in 'class java.lang.String'(示例代相关的知识,希望对你有一定的参考价值。

 

Mybatis版本:mybatis-3.0.6.jar

1.当入参为 string类型时 (包括java.lang.String.) 

我们使用#{xxx}引入参数.会抛异常There is no getter for property named ‘XXX‘ in ‘class java.lang.String‘

技术分享图片
<select id="getBookingCount" resultType="int" parameterType="string">

select count(*) from TB_EMPC_BOOKING_ORDER T

where (t.state = ‘1‘ or t.state = ‘2‘)

and t.appointmenttime = #{state}

</select>
技术分享图片

 

2.解决方法一:把#{xxx}修改为 #{_parameter} 即可

技术分享图片
<select id="getBookingCount" resultType="int" parameterType="string">

select count(*) from TB_EMPC_BOOKING_ORDER T

where (t.state = ‘1‘ or t.state = ‘2‘)

and t.appointmenttime = #{_parameter}

</select>
技术分享图片

 

 

3.解决方法二:可以在方法中提前定义:

public int  methodName(@Param(value="state") String state ){

  ...

}

 

 

4.原因:Mybatis默认采用ONGL解析参数,所以会自动采用对象树的形式取 string.xxx 值,如果没在在方法中定义,则会抛异常报错。

 

5.其他mybatis的版本不知道有没有这个问题,暂时没试过.

 

以上是关于Mybatis异常There is no getter for property named 'XXX' in 'class java.lang.String'(示例代的主要内容,如果未能解决你的问题,请参考以下文章

mybatis 异常 There is no getter for property named 'bizId' in 'class java.lang.Long'(示

Mybatis异常There is no getter for property named 'XXX' in 'class java.lang.String'(示例代

org.apache.ibatis.reflection.ReflectionException: There is no getter for property named XXX 异常的解决办法。

解决Mybatis报错:org.apache.ibatis.reflection.ReflectionException: There is no getter for property named

mybatis There is no getter for property named 'xxxx

mybatis映射异常