英文:
@PostLoad and @PrePersist in Spring Data JDBC project
问题
Spring Data JDBC是否有类似于Spring Data JPA的@PostLoad
和@PrePersist
的功能?
英文:
Does Spring Data JDBC have anything similar to @PostLoad
and @PrePersist
from Spring Data JPA?
答案1
得分: 2
使用Spring Data JDBC,您目前无法直接为实体添加注释。但有生命周期监听器和回调可供您用于相同的目的。
其中一个示例:
@Component
class UserCallbacks implements BeforeConvertCallback<User>,
BeforeSaveCallback<User> {
@Override
public Person onBeforeConvert(User user) {
return // ...
}
@Override
public Person onBeforeSave(User user) {
return // ...
}
}
英文:
With Spring Data JDBC you currently can't annotate the entity directly. But there are life cycle listeners and callbacks that you can use for the same purpose.
One of the examples given:
@Component
class UserCallbacks implements BeforeConvertCallback<User>,
BeforeSaveCallback<User> {
@Override
public Person onBeforeConvert(User user) {
return // ...
}
@Override
public Person onBeforeSave(User user) {
return // ...
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论