Jpa更新得到结果
是否可以知道更新是否正确完成,至少更新了一项数据?
public void userForgetPassword(String email) {
String resetPasswordKey = ...;
userRepository.userForgetPassword(email, resetPasswordKey);
mailService.sendHtmlMail(email);
}
@Modifying
@Query("update User u set u.resetKey=:resetKey, u.enabled=false where u.username=:email")
void userForgetPassword(@Param("email") String email, @Param("resetPasswordKey") String resetPasswordKey);
因为我只想在更新有效的情况下发送电子邮件。
我可以在更新之前验证电子邮件...但我想避免。
Is it possible to know if the update was done correctly, at least one data was updated?
public void userForgetPassword(String email) {
String resetPasswordKey = ...;
userRepository.userForgetPassword(email, resetPasswordKey);
mailService.sendHtmlMail(email);
}
@Modifying
@Query("update User u set u.resetKey=:resetKey, u.enabled=false where u.username=:email")
void userForgetPassword(@Param("email") String email, @Param("resetPasswordKey") String resetPasswordKey);
Because i would like to send email only if update has worked.
I can verify email before update... but i would like to avoid.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以返回
int
而不是void
。返回的数字指定修改的行数。请参阅 使用 @Modifying 更新查询的示例
You can return an
int
instead ofvoid
. The number returned specifies the number of modified rows.See example at Update Queries With @Modifying