1、数据不存在insert;
2、数据存在update;
3、表中有一个唯一约束;并根据该约束执行具体的插入或者修改操作。
————————————————————————————
insert into T_name (uid, app_id,createTime,modifyTime)
values(111, 1000000,'2017-03-07 10:19:12','2017-03-07 10:19:12')
on duplicate key update uid=111, app_id=1000000, createTime='2017-03-07 10:19:12',modifyTime='2017-05-07 10:19:12'
如何把上边的sql,用mybatis改写?
ringa_lee2017-04-18 10:50:33
<insert id="upsert" parameterType="Model">
insert into T_name
(uid, name, age, balance) values (100,"yangyang", 23, 100000000)
on duplicate key update balance=balance + 100
</insert>
You can test the above code by yourself.
阿神2017-04-18 10:50:33
<insert id="upsert" parameterType="Model">
insert into T_name
(uid, name, age, balance) values (#{uid,jdbcType=VARCHAR},#{name}, 23, 100000000)
on duplicate key update balance=balance + 100
</insert>
Use #{} in my mybatis to get the vo attribute value