记录
用mybatis-plus写后端代码时出现了如下的问题
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.springboot.mapper.BooksMapper.selectById
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.springboot.mapper.BooksMapper.selectById
大多数的解决方式为在对应的属性上添加@TableId
注解
此种解决方式可以用于由于变量名称存在部分错误的情况下进行
但是当添加后依旧会出现
org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'isbn' in 'class com.baomidou.mybatisplus.core.conditions.query.QueryWrapper'
org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'isbn' in 'class com.baomidou.mybatisplus.core.conditions.query.QueryWrapper'
此时查找许多内容均没有解决该问题,后检查出为代码逻辑出现问题
QueryWrapper<Books> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("ISBN",ISBN);
Books books = booksMapper.selectById(queryWrapper);
该代码的目的为查找出按照主键查找书籍,然而这种方式会出错,使用
QueryWrapper<Books> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("ISBN",ISBN);
Books books = booksMapper.selectOne(queryWrapper);
或者是
Books books = booksMapper.selectById(ISBN);
均可正确实现功能不报错
思考
在代码逻辑上的错误不容易被察觉,这个地方只是提供一个解决的思路,不会遇到这种问题是最好不过了
标签:queryWrapper,ISBN,QueryWrapper,binding,bound,ibatis,statement,apache,org From: https://www.cnblogs.com/chen94013/p/16970667.html