关于Mybatis的There is no getter for property named 'xxxx '错误

来源:互联网 发布:网络宣传计划书范文 编辑:程序博客网 时间:2024/05/23 00:37

mybatis查询时报
There is no getter for property named ‘xxxx’ in ‘class java.lang.Integer’ 错误。查看sql发现有一个Integer类型的参数,以下为sql写法:

SELECT    <include refid="Base_Column_List" />    FROM hotel    <where>      <if test="hotelPkid != null and hotelPkid != ''">        AND hotel_pkid =#{hotelPkid }      </if>      <if test="hotelName != null and hotelName != ''">        AND hotel_name like concat('%', #{hotelName} ,'%')      </if>    </where>    ORDER BY hotel_pkid 

此处报 There is no getter for property named ‘hotelPkid ’ in ‘class java.lang.Integer

从网上查了些资料,解决方法有两种:
1、将 参数名称 “hotelPkid ” 替换为”_parameter” ,结果正常。
2. 在mapper接口中定义方法时增加“@Param(“hotel_pkid “)”,即
List listHotel(@Param(“hotelPkid “)int (hotelPkid );
经本人亲测:方法一可行,方法二不可行,不知道什么原因。
另外对于方法一也可以将_parameter 改为 value 也是可以的!具体原因不明!
参考:
http://blog.csdn.net/woshixuye/article/details/8820387
http://blog.sina.com.cn/s/blog_8ced01900101blqd.html

阅读全文
0 0