PagingAndSortingRepository通过url调用findFooInBar

时间:2018-04-04 09:12:43

标签: rest spring-boot spring-data-jpa

我最近开始使用带有PagingAndSortingRepository的spring-boot。

@RepositoryRestResource(collectionResourceRel = "foobar", path = "foobar")
public interface MyRepository extends PagingAndSortingRepository<FooEntity, Long>{

    List<FooEntity> findAllByStatusIn(@Param("stati") Collection<Integer> stati);

}

如何通过findAllByStatusIn

等网址调用来呼叫http://localhost:8080/foobar/search/findAllByStatusIn?stati={3,1}

我已经尝试过了:

http://localhost:8080/foobar/search/findAllByStatusIn?stati=(3,1)

http://localhost:8080/foobar/search/findAllByStatusIn?stati=[3,1]

http://localhost:8080/foobar/search/findAllByStatusIn?stati={3,1}

http://localhost:8080/foobar/search/findAllByStatusIn?stati=3,1

1 个答案:

答案 0 :(得分:0)

稍微修改我的PagingAndSortingRepository后:

@RepositoryRestResource(collectionResourceRel = "pstnachrichten", path = "pstnachrichten")
public interface PSTNachrichtenRepository extends     PagingAndSortingRepository<PSTNachrichtenEntity, Long>{

    List<PSTNachrichtenEntity> findAllByStatusIn(@Param("stati") int... stati);

}

我能够按如下方式调用资源:

http://localhost:8080/foobar/search/findAllByStatusIn?stati=3&stati=1

因此,诀窍是重复网址中的名称值对。