<insert id="方法名">
<selectKey keyProperty="count"
resultType="java.lang.Integer" order="BEFORE">
select count(1)
from 表名
where user_id= #{3} and code=#{0}
</selectKey>
<if test="count==0">
insert into 表名
( code,
phone_num, user_id)
values
( #{1}, #{2}, #{3})
</if>
<if test="count>0">
update 表名
SET code = #{1},
phone_num = #{2}
WHERE
user_id= #{3} and code=#{0}
</if>
</insert>
mybatis操作数据库,有则更新,无则插入
最新推荐文章于 2024-06-18 17:23:51 发布