@PostLoad和@PrePersist在Spring Data JDBC项目中

huangapple go评论42阅读模式
英文:

@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 // ...
	}
}

huangapple
  • 本文由 发表于 2023年2月16日 04:06:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75464955.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定