Invalid bound statement (not found): com.shizongger.chapter2.mapper.UserMapper.insertUser
2017-06-08 21:50
363 查看
在配置MyBatis时报错信息如下:
Invalid bound statement (not found): com.shizongger.chapter2.mapper.UserMapper.insertUser
简单的理解就是找不到正确的语句。一般是由于mapper.xml和mapper.java的文件不匹配造成的。引入映射器大致有四种方法:
1.用文件路径引入映射器
2.用包名引入映射器
3.用类注册引入映射器
4.xxxMapper.xml引入映射器
这四种引入mapper的方式各有特点,我建议使用第一种或者第二种使用扫描的包的方式。但是在使用第二种的时候要注意:一定要把xxxMapper.java和xxxMapper.xml两者名字一模一样!
本次报错的原因是因为本人把UserMapper.xml错写成userMapper.xml,开头使用了小写,导致程序扫描包的时候扫描不到该mapper而出错。
我为什么会犯此错误?因为我在参考《深入浅出MyBatis技术原理与实践》(电子工业出版社-杨开振著)第3章57页的时候,作者给出了userMapper.xml的代码案例,并以小写作为userMapper.xml文件的开头。且在72页用到mapper.xml的地方,作者都有小写作为mapper.xml开头的习惯,本人误认为是MyBatis默认要求符合驼峰命名法且第一字母必须小写而导致的。
所以,在这里奉劝写技术书籍的作者不要浮躁,要对得起读者啊!
Invalid bound statement (not found): com.shizongger.chapter2.mapper.UserMapper.insertUser
简单的理解就是找不到正确的语句。一般是由于mapper.xml和mapper.java的文件不匹配造成的。引入映射器大致有四种方法:
1.用文件路径引入映射器
<mapper resource="com/shizongger/chapter2/mapper/RoleMapper.xml" /> <mapper resource="com/shizongger/chapter2/mapper/UserMapper.xml" />
2.用包名引入映射器
<package name="com.shizongger.chapter2.mapper" />
3.用类注册引入映射器
<mapper class="com.shizongger.chapter2.mapper.UserMapper" /> <mapper class="com.shizongger.chapter2.mapper.RoleMapper"/>
4.xxxMapper.xml引入映射器
<mapper url="file:/home/shizongger/workspace/Chapter3/src/com/shizongger/chapter2/mapper/RoleMapper.xml" /> <mapper url="file:/home/shizongger/workspace/Chapter3/src/com/shizongger/chapter2/mapper/UserMapper.xml"/>
这四种引入mapper的方式各有特点,我建议使用第一种或者第二种使用扫描的包的方式。但是在使用第二种的时候要注意:一定要把xxxMapper.java和xxxMapper.xml两者名字一模一样!
本次报错的原因是因为本人把UserMapper.xml错写成userMapper.xml,开头使用了小写,导致程序扫描包的时候扫描不到该mapper而出错。
我为什么会犯此错误?因为我在参考《深入浅出MyBatis技术原理与实践》(电子工业出版社-杨开振著)第3章57页的时候,作者给出了userMapper.xml的代码案例,并以小写作为userMapper.xml文件的开头。且在72页用到mapper.xml的地方,作者都有小写作为mapper.xml开头的习惯,本人误认为是MyBatis默认要求符合驼峰命名法且第一字母必须小写而导致的。
所以,在这里奉劝写技术书籍的作者不要浮躁,要对得起读者啊!
相关文章推荐
- mybatis Invalid bound statement (not found)
- springmvc+mybatis 诡异问题 Invalid bound statement (not found)
- spring boot mybatis Invalid bound statement (not found)
- Invalid bound statement (not found)错误
- MyBatis Invalid bound statement (not found)错误
- Invalid bound statement (not found)
- Invalid bound statement (not found)
- Invalid bound statement (not found)
- Invalid bound statement (not found): com.taotao.mapper.TbItemMapper.selectByExample: 错误
- Invalid bound statement (not found): com.zc.product.dao.IFancyMapper.totalPage
- Maven项目mybatis Invalid bound statement (not found)解决方法
- Invalid bound statement (not found):
- Invalid bound statement (not found): com.yu.test.dao.TaskDao.findById
- Invalid bound statement (not found)错误的可能原因
- Invalid bound statement (not found): com.xs.vote.dao.UserDao.get
- Invalid bound statement (not found)
- invalid bound statement (not found),大概应该是报mapper.xml中的sql查询和mapper.java中的方法没有绑定成功!
- IDEA中 Invalid bound statement (not found)解决方法
- Invalid bound statement (not found)问题
- Mybatis——Invalid bound statement (not found)-Could not find result map java.lang.Integer