MYSQL foreach使用

1.批量查询

   select id from a where 1=1
   and(
     <foreach collection="list" item="cus" separator="or">
         name = #{cus}
     </foreach>
     )

2.批量新增

  INSERT INTO a(id, name,remark)
  VALUES
   <foreach collection="List" item="item" index="index" separator=",">
       (
       #{item.id,jdbcType=VARCHAR},
       #{item.name,jdbcType=VARCHAR},
       #{item.remark,jdbcType=VARCHAR}
       )
   </foreach>

3.批量修改

  update a set id = '' where 1=1
  and id in (
   <foreach collection="List" item="id" separator="or">
        #{id}
   </foreach>
   )

4.批量删除

  delete a set id = '' where 1=1
  and id in (
   <foreach collection="List" item="id" separator="or">
        #{id}
   </foreach>
   )

你可能感兴趣的:(mybatis,mysql,java,数据库)