初学者手册-MyBatis踩坑记(org.apache.ibatis.binding.BindingException)
1、参数绑定失败
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'msgs3' not found. Available
parameters are [msgs, param1]
相关信息
<insert id="insertBatch">
INSERT INTO t_user
(id, name, del_flag)
VALUES
<foreach collection ="msgs3" item="user" separator =",">
(#{user.id}, #{user.name}, #{user.delFlag})
</foreach >
</insert>
//Mapper类
public interface UserMapper {
public void insertBatch (List<User> users);
}
分析思路
经过测试发现错误是从map.xml文件报出来的,也就是说,系统是可以读到xml文件的,但是通过xml文件读取对应的参数msgs3时报错。即,问题出在map.java上面。但是,检查了命名,并没有相关问题。
解决方案
既然是绑定的问题,那么问题肯定不是在xml文件上,就是在对应的map的java方法上。所以,有两种解题方法。
值得注意的是:指定了传参名称以后,默认值就会失效
1、修改xml文件
通过测试发现,foreach 中的collection貌似默认值为 list,当不指定传参的名称时,可以直接使用。
<insert id="insertBatch">
INSERT INTO t_user
(id, name, del_flag)
VALUES
<foreach collection ="list" item="user" separator =",">
(#{user.id}, #{user.name}, #{user.delFlag})
</foreach >
</insert>
2、修改Mapxx.java中的方法参数
//Mapper类
public interface UserMapper {
public void insertBatch (@Param("msgs") List<User> users);
}
初学者手册-MyBatis踩坑记(org.apache.ibatis.binding.BindingException)的更多相关文章
- IDEA+Maven+Mybatis 巨坑:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.rao.mapper.UserMapper.findAll
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.rao.mapper.User ...
- idea 单元测试 mybatis spring-test 异常: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
因为在idea中必须在test下才能进行单元测试,所以进行单元测试时,ssm的项目会因为找不到resourece中的配置文件而报错 这里 org.apache.ibatis.binding.Bindi ...
- Mybatis笔记二:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
错误异常:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.test.dao.N ...
- mybatis配置时出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
如果出现: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 一般的原因是Mapper i ...
- mybatis plus 报错 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 少了个范型
- MyBatis典型的错误org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
XXXmapper.java(接口) XXXmapper.xml(结果集映射) //此两个文件要在统一包下,且xml中的namespace是唯一的,为了区分须写成 该xml的全路径
- mybatis-plus报org.apache.ibatis.binding.BindingException分析【转载】
这个问题整整纠结了我四个多小时,心好累啊...不废话... 背景:Spring整合Mybatis 报错:org.apache.ibatis.binding.BindingException: Inva ...
- org.apache.ibatis.binding.BindingException【原因汇总】
这个问题整整纠结了我四个多小时,心好累啊...不废话... 背景:Spring整合Mybatis 报错:org.apache.ibatis.binding.BindingException: Inva ...
- 【踩坑】遇到 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 报错
今天在重做 iblog 客户端时,测试接口情况,发现了 org.apache.ibatis.binding.BindingException: Invalid bound statement (not ...
随机推荐
- IOC与DI简介
IOC:控制反转(Inverse Of Control) 在没用spring框架之前我们是这样写程序的: private UserDao userDao = new UserDaoImpl(); 也就 ...
- flask中过滤器的使用
过滤器 过滤器的本质就是函数.有时候我们不仅仅只是需要输出变量的值,我们还需要修改变量的显示,甚至格式化.运算等等,而在模板中是不能直接调用 Python 中的某些方法,那么这就用到了过滤器. 使用方 ...
- Android 框架学习2:源码分析 EventBus 3.0 如何实现事件总线
Go beyond yourself rather than beyond others. 上篇文章 深入理解 EventBus 3.0 之使用篇 我们了解了 EventBus 的特性以及如何使用,这 ...
- NSArray中的对象进行排序
看在iOS中有哪些方法可以对NSArray中的对象进行排序.下面是目录: 小引 使用NSComparator进行排序 使用NSDescriptor进行排序 使用selector进行排序 小引 我们将要 ...
- 关于python的包
参考文献:http://blog.sina.com.cn/s/blog_615c388d01017b5o.html 注:本文大多对上连接的整理,仅用于学习,望博主见谅.转载请附上上述链接. 为什么要包 ...
- ibatis 参数类型为map,map里面有list
<select id="getChannelLayerList" parameterClass="java.util.HashMap" re ...
- 实现Python代码发送邮件
import smtplib from email.mime.text import MIMEText from email.utils import formataddr msg = MIMETex ...
- Centos kvm+ceph
Centos kvm+ceph 一. centos6.5 安装kvm 1. disable selinux 2. 确认支持intel虚拟化 3. 安装需要的包 4.设置桥接网络 5.运行kvm ins ...
- bzoj 4573 大森林
bzoj 4573 大森林 由于树上路径是唯一的,查询合法的两个点间路径长度显然与其他加点操作无关,所以可以离线处理,将所有的查询放在加点后. 这样我们可以对每棵树都在上颗树的基础上处理好形态后,处理 ...
- MySQL的一些常用sql函数(持续更新。。)
1. 字符串拼接函数 :CONCAT(str1,str2,...) SELECT CONCAT('AAA','BBB') STR; //AAABBB 2. 判断是否为null,为null就指定另外一个 ...