Not sure, but I'll take a shot. When you use #{key}
, MyBatis puts extra ''
around it if it is a String
, Date
etc. If you give your column names with a variable you need to use direct String
replacement which is ${key}
.
The error log says something like ...right syntax to use near ''name') VALUES ('some value'...
Can you try
<insert id="createNews" parameterType="map" useGeneratedKeys="true" keyColumn="id">
INSERT INTO t
<foreach item="key" collection="Key" index="index" open="(" separator="," close=")">
${key}
</foreach>
VALUES
<foreach item="value" collection="Value" index="index" open="(" separator="," close=")">
#{value}
</foreach>
</insert>