1. 程式人生 > >mybatis將list集合插入到MySQL

mybatis將list集合插入到MySQL

<insert id="intsertAllUserIdsAndMsg" parameterType="java.util.List">
    insert into User_Msg(
    user_id,
    msg_id,
    `read`,
    `type`,
    crt_time
    )
    values
    <foreach collection="list" item="item" index= "index" separator =",">
        (
        #{item.userId},
        #{item.smsId},
        #{item.read},
        #{item.type},
        NOW()
        )
    
</foreach> </insert>
需要注意read和type關鍵字用`符號,Tab鍵上面那個,不是單引號