最近在开发过程中遇到了一个问题,上网百度都不能解决,后来还是看项目中类似的代码才解决的。
原有代码:
@Override
public Students getById(Integer id) {
Example example = new Example(Students.class);
example.createCriteria()
.andEqualTo(Students.ID,id);
return studentsMapper.selectByPrimaryKey(example);
}
完整报错信息如下:
" nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'id' in 'class tk.mybatis.mapper.entity.Example' "
通过主键查找,就不用中间部分的代码了,直接返回即可。
修改后的代码如下:
@Override
public Students getById(Integer id) {
return studentsMapper.selectByPrimaryKey(id);
}