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>