使用 Spring Data Repository 保存后是否仍然要记录

Is there anyway to log after save with Spring Data Repository

我正在尝试在使用 Spring 数据存储库保存实体后记录一些信息,还有吗?

谢谢!

您可以使用 Annotated repo event handlers.

只需将 @RepositoryEventHandler 注释添加到您的处理程序 class,而不是在此 class 中使用 @HandleAfterCreate 实现处理程序方法@HandleAfterSave 注释。

    @RepositoryEventHandler 
    public class EventHandler {

      @HandleAfterCreate
      @HandleAfterSave
      public void handleAfterCreateOrSave(Entity e) {
        // LOG...
      }
    }