Mybatis中报“There is no getter for property named ‘XXX‘ in class java.lang.String“

本文讲述了在MyBatis中,如何解决因误将参数映射为String导致的查找`result`属性getter方法失败的问题,给出了两种修正方法:一是修改mapper.xml文件中的参数判断,二是将result标记为MyBatis特殊标识。

XXMapper.xml 如下:

    <!--查询日志信息总数-->
    <select id="getLogCount" parameterType="String" resultType="int">
        select count(URL) TOTALCOUNT FROM TC_LOG 
        <if test="result!=null">
        where RESULT=#{result}
        </if>
    </select>

Dao层 如下:

/**
	 * 查询日志信息总数
	 */
	public int getLogCount(String result);

在调用的时候:

严重: Servlet.service() for servlet [springMVC] in context with path [/UAP] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘result’ in ‘class java.lang.String’] with root cause
org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘result’ in 'class java.lang.String’

解决:

第一种方法:发现问题出在映射文件里,如果参数使用java.lang.String的时候,需要将result改成_parameter来判断是否为空,否则它回去String这个类型里找result的getter方法,所以无法找到。
修改XXMapper.xml:
在这里插入图片描述

第二种方法:将result标记为mybatis可识别的标识,这样也不会去调用String这个类型里找result的getter方法。
修改Dao
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值