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

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

被折叠的 条评论
为什么被折叠?



