项目中经常的需要使用批量操作语句对数据进行操作,使用批量语句的时候需要注意MySQL数据库的条件限制,这里主要是数据的大小限制,这里对批量插入、批量查找及批量更新的基础操作进行下简单的汇总。
insert id=”addTextPushList”paramerterType = “java.util.List”>
INSERT INTO SYS_TEXT_PUSH(
PUSH_ID,
USER_UM_ACCOUNT,
USER_NAME,
SECTION,
USER_MOBILE,
PUSH_STATUS,
PROMOTE_ID,
CREATED_BY,
CREATION_DATE,
ENABLED_FLAG
)values
foreach collection=”list” item = “item” separator=”,”>
(
#{item.pushId},
#{item,userUmAccount},
#{item.userName},
#{item.section},
#{item.userMobile},
#{item.pushStatus},
#{item.promoteId},
#{item.createdBy},
#{item.creationDate},
#{item.enabledFlag}
)
/foreach>
/insert>
select id = “getTextPromoteByIds” parameterType = “java.util.list” resultMap = “textPromoteMap”>
SELECT
*
FROM SYS_TEXT_PROMOTE
WHERE
TEXT_PUSH_FLAG = 1
AND PROMOTE_ID IN
foreach collection=”list” item = “item” open=”(” separator=”,” close =”)”>
#{item}
/foreach>
/select>
update id = “updatePushStatus” parameterType = “java.util.List”>
update
SYS_TEXT_PUSH
SET
PUSH_STATUS = 1,
LAST_UPDATE_DATE = NOW()
WHERE
PUSH_ID IN
foreach collection=”list” item = “item” open=”(” separator=”,” close =”)”>
#{item}
/foreach>
/update>
update id = “updatePushStatus” parameterType = “java.util.List”>
foreach collection=”list” item = “item” index = “index”>
update
SYS_TEXT_PUSH
SET
PUSH_STATUS = #{item.pushStatus},
LAST_UPDATE_DATE = NOW()
WHERE
PUSH_ID = #{item.pushId}
/foreach>
/update>