Spring Repository:获取已删除的行数 [英] Spring Repository: get number of deleted rows

查看:29
本文介绍了Spring Repository:获取已删除的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过 Spring Repository 自定义查询获取已删除行的计数(我正在为应用程序实现基本的外部锁定机制,并且仅限于 MySQL 数据库).我怎样才能做到这一点?

I'm in need of getting count of deleted rows by Spring Repository custom query (i'm implementing basic external lock mechanism for application and is limited to MySQL database only). How can i achieve that?

推荐答案

使用 @Modifying 注释如下所述:

Create a repository method with the @Modifying annotation as described here:

@Modifying
@Query("delete from data where createdAt < ?1")
int retainDataBefore(Date retainDate);

返回值为您提供已删除行的计数.

Return value gives you the count of deleted rows.

这篇关于Spring Repository:获取已删除的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆