美文网首页
Mybatis异常There is no getter for

Mybatis异常There is no getter for

作者: 帅气的名称被占用 | 来源:发表于2019-05-24 18:55 被阅读0次

[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="getXxxxCount" 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></pre>

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

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

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

相关文章

网友评论

      本文标题:Mybatis异常There is no getter for

      本文链接:https://www.haomeiwen.com/subject/vlbnzqtx.html