问题
I am trying to find any info regarding the following issue: I have a JPA repository which was exposed to REST service with Spring Data Rest project:
Page<Business> findByUser(@Param("user") User user, Pageable pageable);
where the user
parameter is the entity.
Now when I try to call this REST method from client (with RestTemplate or Traverson) I can't understand how should I pass this param...
Is it possible to implement it without making custom controller?
Thank you in advance
回答1:
I am assuming User
is another Spring Data REST managed entity? If so you pass a URI identifying the user you'd like to hand into the method to the query method resource.
Traverson traverson = new Traverson(…);
traverson.follow("businesses", "search", "findByUser")
.withTemplateParameters(Collections.singletonMap("user", "…/users/4711")).…
回答2:
I finally figured it out. Look at this issue on Spring JIRA.
The way to request this depends on your version of Spring Data Rest. If you have a version 2.4+, you have to use the URI. If you have an older version, you have to use the primary key.
So you may need to expose your primary keys if you have an older version of SDR. This question could help you in managing that.
来源:https://stackoverflow.com/questions/29897351/the-way-of-passing-complex-params-into-spring-date-rests-method