Skip to content

Instantly share code, notes, and snippets.

@diaolizhi diaolizhi/insert.java
Last active Jan 7, 2019

Embed
What would you like to do?
mysql 插入数据时如果存在主键则只更新
@Insert("INSERT INTO t_email_link VALUES (#{email}, #{link}, DATE_ADD(CURDATE(), INTERVAL 2 DAY))" +
"ON DUPLICATE KEY UPDATE link=#{link}, exp=DATE_ADD(CURDATE(), INTERVAL 2 DAY)")
void saveEmailAndChangePasswordLink(@Param("email") String email, @Param("link") String link);
//重点是 ON DUPLICATE KEY UPDATE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.