spring data jpa 操作监听器

配置监听器

public class StudentEntityListener {
	@PrePersist // 保存前
	public void prePersist(Student student) {
		log.info("保存前" + student.toString());
	}

	@PostPersist // 保存后
	public void postPersist(Student student) {
		log.info("保存后" + student.toString());
	}

	@PreRemove // 删除前
	public void preRemove(Student student) {
		log.info("删除前" + student.toString());
	}

	@PostRemove // 删除后
	public void postRemove(Student student) {
		log.info("删除后" + student.toString());
	}

	@PreUpdate // 更新前
	public void preUpdate(Student student) {
		log.info("更新前" + student.toString());
	}

	@PostUpdate // 更新后
	public void postUpdate(Student student) {
		log.info("更新后" + student.toString());
	}

	@PostLoad // 查询后
	public void postLoad(Student student) {
		log.info("查询后" + student.toString());
	}
}

在实体类上添加注解

@EntityListeners(value = {StudentEntityListener.class})
public class Student implements Serializable {}

你可能感兴趣的:(spring data jpa 操作监听器)