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,而非其他的。作为惩罚,写到博客里,加深自己的印象,如果能帮助别人遇到这个问题而不知道怎么解决,便再好不过了。
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)