报错:运算至少需要包含一个列
原始写法
<insert id="insertComments" parameterType="Map">
insert into items_comments
(
id,
user_id,
item_id,
item_name,
item_spec_id,
sepc_name,
comment_level,
content,
created_time,
updated_time
)
values
<!-- <foreach collection="paramsMap.list" index="index" item="item" separator="," open="(" close=")">-->
<foreach collection="paramsMap.list" index="index" item="item" separator="," >
(
#{item.id},
#{paramsMap.userId},
#{item.itemId},
#{item.itemName},
#{item.itemSpecId},
#{item.itemSpecName},
#{item.commentLevel},
#{item.content},
now(),
now()
)
</foreach>
</insert>
错误原因:注释掉的那一行多出来open="(" close="),导致多了左右括号,识别不了字段列
mybatis变异后错误的sql为
insert into items_comments (id,
user_id,
item_id,
item_name,
item_spec_id,
sepc_name,
comment_level,
content,
created_time,
updated_time)
values ((?, ?, ?, ?, ?, ?, ?, ?, now(), now()), (?, ?, ?, ?, ?, ?, ?, ?, now(), now()))