Spring Data Repo General Criteria

2019-07-24 17:15发布

I have a Spring Data repository with multiple find methods like below.

@Repository
public interface UsersRepository extends 
CrudRepository<UserView>, Integer> {

@Override
Optional<Users> findById(Integer aLong);
List<Users> findAllAccountNotNull...
List<Users> findAllThat....
List<Users> findAllThisToo....
....

}

Now according to a new requirement, I want to add a criteria to ALL of this methods for example,

List<Users> findAll...NotInUserBlocked

So all above find statements should work with a common criteria of "find all users only who are not blocked". I can add this one by one to all find methods and also update all the methods that are calling these. But there are many. Is there a better way of doing this from a central place? And more cleanly?

Edit: Please note that this is a view. And the soft delete I want to make is on a different entity(Account). So A field in User view is constructed by taking into account User.Account.isNotBlocked.

0条回答
登录 后发表回答