Mybatis_ReflectionException:There is no getter for property named 'distinct' in 'class tk.mybatis

1. 发生异常的背景
 情景:
我在Service层里面继承了通用mapper接口,其中有一个方法是selectByExample,然后在调用的时候报了一个org.apache.ibatis.reflection.ReflectionException错误,详情如下:

// 所报的主要异常如下:
org.mybatis.spring.MyBatisSystemException: 
	nested exception is org.apache.ibatis.reflection.ReflectionException: 
	There is no getter for property named 'distinct' in 'class tk.mybatis.mapper.entity.Example$Criteria'
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:79)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447)
	at com.sun.proxy.$Proxy136.selectList(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:231)
	at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
	at com.sun.proxy.$Proxy164.selectByExample(Unknown Source)

 我所调用方法如下:
所用方法

 
2. 原因以及解决方法
因为我所传参数不对,不管这边传泛型T还是传criteria,都会报该错误。

  • 解决方法:解决方法
    因为自己粗心,写快了。mapper.selectByExample()方法里面应该传入的参数是example,而非其他的。作为惩罚,写到博客里,加深自己的印象,如果能帮助别人遇到这个问题而不知道怎么解决,便再好不过了。
发布了204 篇原创文章 · 获赞 69 · 访问量 19万+

猜你喜欢

转载自blog.csdn.net/pseudonym_/article/details/100112223