Mybatis异常总结

1.异常

nested exception is org.apache.ibatis.exceptions.PersistenceException: \n### Error querying database.  Cause: java.lang.UnsupportedOperationException\n### The error may exist in class path resource [conf/mapper/com/ppdai/cbd/thirdparty/userthirddata/NoInsertColumnsQueryMapper.xml]\n### The error may involve com.ppdai.cbd.thirdparty.dao.mapper.userthirddata.NoInsertColumnsMapper.selectDataCutFill\n### The error occurred while handling results\n### SQL: SELECT * from no_insertcolumns WHERE updatestatus = 0;\n### Cause: java.lang.UnsupportedOperationException

原因  

      SELECT * from 表名 WHERE updatestatus = 0;

mybatis 设置resultType为java.util.List  因为最终结果会是list,但是mybatis的resultType指的是单条记录的类型,所以应该改成 java.util.Map或者对象。

2.异常

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

一般的原因是Mapper interface和xml文件的定义对应不上,需要检查包名,namespace,函数名称等能否对应上,需要比较细致的对比,我经常就是写错了一两个字母搞的很长时间找不到错误

按以下步骤一一执行:

1:检查xml文件所在的package名称是否和interface对应的package名称一一对应

2:检查xml文件的namespace是否和xml文件的package名称一一对应

3:检查函数名称能否对应上

4:去掉xml文件中的中文注释

5:随意在xml文件中加一个空格或者空行然后保存

一般来说到此就可以排除错误了  检查xml和java mapper是不是匹配。

posted @ 2018-07-27 15:49  安琪拉的博客(公众号)  阅读(451)  评论(0编辑  收藏  举报