英文:
Customize 'find' logic in JPA repositories
问题
我有以下问题想向社区提问:是否有办法自定义所有我的 JPA 仓库的“查找”逻辑?
例如,我希望我的自定义“查找”逻辑在每次在我的 JPA 仓库中创建包含单词“查找”的方法时自动被调用(findAll、findById、findOne 等)。
我正在尝试按照官方文档(https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.customize-base-repository)进行操作,但我不确定我是否做错了什么,或者是否无法通过这种策略实现我心中所想的内容。
提前感谢您的帮助。
英文:
I have the following question for the community: is there any way to customize the 'find' logic for all my JPA repositories?
For example, I would like my custom 'find' logic to be invoked automatically everytime a method containing the word 'find' is created in my JPA repositories (findAll, findById, findOne, ..).
I'm trying to follow the official documentation (https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.customize-base-repository) but I don't understand if I'm doing something wrong or if it's not possible to implement what I have in mind with this straregy.
Thank you in advance.
答案1
得分: 0
你可以使用Spring AOP
来实现它(我建议你阅读文档)。当使用注解时,你的切入点表达式(在切面内部)应该如下所示:
@Pointcut("execution(*org.yourpackage.repositories.*.find*(..))")
public void customFind() {
//...
}
英文:
You can do it with the use of Spring AOP
(I suggest you read the docs). When using annotations, your pointcut expression (inside an aspect) would look like so:
@Pointcut("execution(*org.yourpackage.repositories.*.find*(..))")
public void customFind() {
//...
}
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论