您的位置:首页 > 编程语言

mybatis中批量插入与批量更新代码,仅供参考

2018-01-31 14:38 295 查看
批量插入案例:

<insert id="insertList">
insert into t_area_open
<trim prefix="(" suffix=")" suffixOverrides="," >
`rowid`,
fid,
fprovince_name,
fprovince_code,
fcity_name,
fcity_code,
fstatus,
fcreatetime,
fupdatetime,
foperator,
</trim>
values
<foreach collection="list" item="item" separator=",">
<trim prefix=" (" suffix=")" suffixOverrides="," >
#{ item.rowid,jdbcType=INTEGER },
#{ item.fid,jdbcType=VARCHAR },
#{ item.fprovinceName,jdbcType=VARCHAR },
#{ item.fprovinceCode,jdbcType=TINYINT },
#{ item.fcityName,jdbcType=VARCHAR },
#{ item.fcityCode,jdbcType=SMALLINT },
#{ item.fstatus,jdbcType=INTEGER },
#{ item.fcreatetime,jdbcType=TIMESTAMP },
#{ item.fupdatetime,jdbcType=TIMESTAMP },
#{ item.foperator,jdbcType=VARCHAR },
</trim>
</foreach>
</insert>

批量更新:

<update
id="updateIntegral"
parameterType="java.util.List"
>
    UPDATE t_integral
    SET
    fupdatetime =
    <foreach
collection="list5"
item="integral"
separator=" "
open="case fid"
close="end"
>
       WHEN #{integral.id,jdbcType=VARCHAR} THEN NOW()
    </foreach>
    ,fintegral =
    <foreach
collection="list5"
item="integral"
separator=" "
open="case fid"
close="end"
>
       WHEN #{integral.id,jdbcType=VARCHAR} THEN #{integral.integral,jdbcType=DECIMAL}
    </foreach>
        WHERE fid IN
    <foreach
collection="list5"
item="integral"
separator=","  open="("
close=")"
>
    #{integral.id,jdbcType=VARCHAR}
    </foreach>
    AND fkeyarea IN
    <foreach
collection="list5"
item="integral"
separator=","  open="("
close=")"
>
    #{integral.areaKey,jdbcType=SMALLINT}
    </foreach>
</update>
有不明白的可以留言.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: