public interface SomethingMapper {
@Insert({
"<script>",
"INSERT INTO your_database_name.your_table_name",
"(column1_int, column2_str, column3_date, column4_time)",
"VALUES" +
"<foreach item='each_item_name' collection='theCollection' open='' separator=',' close=''>" +
"(" +
"#{each_item_name.column1,jdbcType=INTEGER},",
"#{each_item_name.column2,jdbcType=VARCHAR},",
"(SELECT SOME_DB_FUNCTION(#{each_item_name.column3,jdbcType=DATE})),",
"#{each_item_name.period.start,jdbcType=TIME}" +
")" +
"</foreach>",
"</script>"})
void insertBatchSomething(@Param("theCollection") List<Something> theCollection);
}
<insert id="insert" parameterType="java.util.List">
INSERT INTO games (
id,
game_id,
game_vendor,
game_code,
game_name,
game_type)
VALUES
<foreach collection="list" item="element" index="index" open="(" separator="),(" close=")">
#{element.id},
#{element.gameId},
#{element.gameVendor},
#{element.gameCode},
#{element.gameName},
#{element.gameType},
</foreach>
</insert>
参考: