Spring Data Rest: Return Resources of User

后端 未结 3 1907
一生所求
一生所求 2020-12-09 23:56

I\'m creating a simple CRUD-App (a shoppinglist) with Spring Boot and Spring Data Rest. I have a resource: ShoppingItem. Is there an easy way to only return the

3条回答
  •  死守一世寂寞
    2020-12-10 00:55

    If you are using Spring security integration you can use ACL (maybe to heavy) or simple postFilter like following:

    public interface ShoppingItemRepository extends CrudRepository {
        @PostFilter("filterObject.user.getId() == principal.id")
        @Override
        Iterable findAll();   
    }
    

提交回复
热议问题