The way of passing complex params into spring date rest's method

不问归期 提交于 2019-12-12 04:39:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!