用于软删除的spring-data-mongodb的查询拦截器 [英] Query interceptor for spring-data-mongodb for soft deletions

查看:50
本文介绍了用于软删除的spring-data-mongodb的查询拦截器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 where 条件添加到所有存储库获取方法中,以便不查看已删除的项目.在 Spring JPA 中,可以向实体添加 @Where 注释.但是对于 Spring Data MongoDB AFAIK,这是不可能的.尝试过 Mongodb 生命周期事件但没有成功.有没有办法在执行前修改存储库查询.

I want to add where condition to all repository fetching methods for not viewing deleted items. In Spring JPA it's possible to add @Where annotation to Entity. But for Spring Data MongoDB AFAIK it's not possible. Tried Mongodb lifecycle events but not succeeded. Is there a way of modifying repository queries before execution.

推荐答案

您能解释一下查看已删除的项目"是什么意思吗?如果需要,您可以使用 MongoTemplate 并编写自己的存储库,因此可以为每个方法添加所需的 where 条件

Can you explain what do you mean with "viewing deleted items"? If you want, you can use MongoTemplate and write your own repository and so can add desired where condition to every method

这篇关于用于软删除的spring-data-mongodb的查询拦截器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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