Spring Data: Override save method

前端 未结 11 1282
温柔的废话
温柔的废话 2020-11-27 05:30

I\'m considering spring data for a project. Is it possible to override the per default generated save method? And if yes, how?

11条回答
  •  醉话见心
    2020-11-27 05:40

    If you are using interfaces only you can use default methods to do simple overrides of the CrudRepository or JpaRepository:

    
    public interface MyCustomRepository extends CrudRepository {
    
      @Override
      default  S save(S entity)
      {
        throw new UnsupportedOperationException("writes not allowed");
      }
    }
    

提交回复
热议问题