美文网首页
Mysql 动态sql foreach 使用案例

Mysql 动态sql foreach 使用案例

作者: 储僖僧僳儒 | 来源:发表于2018-07-01 21:59 被阅读0次


    <delete id="deleteUser" parameterType="list">
    delete from user where id in
    <foreach collection="list" item="id" open="(" separator="," close=")">
    #{id}
    </foreach>
    </delete>

    <select id="findUserBySex" resultType="user">
    select * from user where name in
    <foreach collection="roleNoList" item="name" index="index" open="(" separator="," close=")">
    #{roleNo}
    </foreach>
    </select>

    <insert id="addUser" parameterType="user" >
    insert into user(name,id,code) values
    <foreach collection="list" item="item" separator=",">
    (#{item.name},#{item.id},#{item.code})
    </foreach>
    </insert>

    <update id="updateUser" parameterType="user">
    update user set a = #{fptm},b=#{csof} where c in
    <foreach collection="list" item="item" open="(" separator="," close=")">
    #{item}
    </foreach>
    </update>

    相关文章

      网友评论

          本文标题:Mysql 动态sql foreach 使用案例

          本文链接:https://www.haomeiwen.com/subject/sqbhuftx.html