spring-data-neo4j有一个beforeSave方法吗?

时间:2015-05-05 14:05:16

标签: java spring neo4j spring-data-neo4j

如何在保存实体之前执行某些代码?

@NodeEntity
public class Person {

    @Transient
    String password
    String passwordHash

    public void beforeSave() { // I made this method name up.
        if (password != null && !password.isEmpty()) {
            passwordHash = AuthenticationService.encodePassword(email, password);
            password = null;
        }
    }
}

我是否需要使用AspectJ,或者使用注释是否有更简单的方法?

我添加了以下依赖项:

compile("org.springframework.data:spring-data-neo4j:3.3.0.RELEASE")
compile("org.springframework.data:spring-data-neo4j-rest:3.3.0.RELEASE")

1 个答案:

答案 0 :(得分:0)

在SDN3中,您有其他Spring Data项目中的BeforeSave ApplicationEvents。

http://docs.spring.io/spring-data/data-neo4j/docs/3.3.0.RELEASE/reference/html/#lifecycle_events