Mybatis传入参数问题
我传入的参数类型是List<Map> 但是在相关mapper文件中,插入语句一直报错。
下边是代码:
java文件中相关代码
int test = 10;
List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
for (int i = 0; i < test; i++) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", i);
map.put("name","name")
list.add(map);
}
this.TestMapper.addTest(list);
Testmapper.xml文件中代码:
<select id="addTest" parameterType="list">
<foreach collection="list" item="item">
insert into test_table
{
id,
name
}
values{
#{item.id}
#{item.name}
}
</foreach>
</select>
报的错误是:
java.lang.reflect.InvocationTargetException
求解答这是为什么会出现错误
------解决方案--------------------首先标签错了,用insert 不能用select,其次循环不对,insert放在循环外。
例: <insert id="credit_Term_insert" parameterType="ArrayList">
insert into TACCOUNTSBATCH
(relationID,
batchID,
batchYear,
batchProperty,
fetchStartTime,
fetchEndTime,
storageTime,
modifyTime,
validStatus
)values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.relationID,jdbcType=VARCHAR},#{item.batchID,jdbcType=VARCHAR},#{item.batchYear,jdbcType=VARCHAR},
#{item.batchProperty,jdbcType=VARCHAR},#{item.fetchStartTime,jdbcType=TIMESTAMP},
#{item.fetchEndTime,jdbcType=TIMESTAMP},