利用myBATIS框架,批量插入数据,测试总是跳出The expression 'msgs' evaluated to a null value异常. MyBatis批量插入insertnull异常 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 xml为什么是<select>标签,而不是<insert>标签?另外这样写不对吧:MsgSmsInfo msg = null;for (int i = 0; i < 6; i++) {msg=new MsgSmsInfo();msgs.add(msg);}应该是for (int i = 0; i < 6; i++) {MsgSmsInfo msg=new MsgSmsInfo();msgs.add(msg);} collection="msgs"msgs 改成 list 就可以了, mybatis中collection的值不代表你传入参数的名字而是一种类型, 官方文档里给出了list和array两种方式 如果是数据库是oracle则改成下面的试试。<select id="bathInsertMsgSmsInfo" parameterType="java.util.List">insert into msg_smsInfo(smsId,receivePhone,sendPhone,msgContent,senderType,sendDate,smsType,aduitType,smsState,bizType,sms_count)values <foreach collection="list" item="item" separator="union all"> select (#{item.smsId,jdbcType=VARCHAR},seq_msg_smsInfo.nextval,#{item.receivePhone,jdbcType=VARCHAR},#{item.sendPhone,jdbcType=VARCHAR},#{item.msgContent,jdbcType=VARCHAR},#{item.senderType,jdbcType=INTEGER},#{item.sendDate,jdbcType=DATE},#{item.smsType,jdbcType=INTEGER},#{item.aduitType,jdbcType=INTEGER},#{item.smsState,jdbcType=INTEGER},#{item.bizType,jdbcType=INTEGER},#{item.sms_count,jdbcType=INTEGER}) from dual </foreach></select> 楼主是用的什么数据库呢。mysql? 正解,如果paramterType为list或者array,那么mybatis会自动将list结构转换为map结构,其中Map的key为list或者array,value为你这里的msgs或者其他,使用时#{list} 加了个拦截器,程序报这个错,求帮忙解决 |f|<1 0≤i≤10 救急 Hibernate保存对象属性为空 问问题啦,Tomcat-6.0.14 ===jdk1.6.0_02 出现了奇怪的问题啦。 能不能把我的程序发上去大家帮我改一下啊 struts标签logic:notEqual 运行错误 weblogic中的连接池问题 AXIS配置问题 jTDS驱动 300分奉上. 详细日志管理,, 求解决方案 研究生选哪个方向好?主要是干什么?
另外这样写不对吧:
MsgSmsInfo msg = null;
for (int i = 0; i < 6; i++) {
msg=new MsgSmsInfo();
msgs.add(msg);
}
应该是
for (int i = 0; i < 6; i++) {
MsgSmsInfo msg=new MsgSmsInfo();
msgs.add(msg);
}
msgs 改成 list 就可以了, mybatis中collection的值不代表你传入参数的名字而是一种类型, 官方文档里给出了list和array两种方式
insert into
msg_smsInfo
(smsId,receivePhone,sendPhone,msgContent,senderType,sendDate,smsType,aduitType,smsState,bizType,sms_count)
values
<foreach collection="list" item="item" separator="union all">
select (#{item.smsId,jdbcType=VARCHAR},seq_msg_smsInfo.nextval,#{item.receivePhone,jdbcType=VARCHAR},#{item.sendPhone,jdbcType=VARCHAR},
#{item.msgContent,jdbcType=VARCHAR},#{item.senderType,jdbcType=INTEGER},#{item.sendDate,jdbcType=DATE},
#{item.smsType,jdbcType=INTEGER},#{item.aduitType,jdbcType=INTEGER},#{item.smsState,jdbcType=INTEGER},
#{item.bizType,jdbcType=INTEGER},#{item.sms_count,jdbcType=INTEGER}) from dual
</foreach>
</select>