mybatis 不存在则才进行添加

# 添加的 sql 语句
insert into sys_link_post_user(post_id,user_id)
# 进行批量添加 (若不需要可以取消 froeach 标签 ),最重要的事 separator='UNION ALL'
<foreach collection="userIds" item="userid" index="index" separator="UNION ALL" >
        # DUAl 是一张临时表,直接可以用,然后 where not exists 中写子查询,若存在(select #{postId},#{userid} from 结果将为空)
            select #{postId},#{userid} from DUAL where not exists( select user_id  from sys_link_post_user where user_id = #{userid} )
        </foreach>

 

相关文章:

  • 2021-06-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-17
  • 2021-08-17
  • 2021-08-01
相关资源
相似解决方案