如何在Spring Data REST导出的端点中使用列表? [英] How to use List in endpoint exported by Spring Data REST?

查看:59
本文介绍了如何在Spring Data REST导出的端点中使用列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个对象,Foo和Bar(一个Foo是@ManyToOne,带Bar),以及Spring Boot 2.0中一个非常基本的存储库接口,以及一个方法:

I have 2 objects, Foo and Bar (a Foo is @ManyToOne with Bar), and a very basic repository interface in Spring Boot 2.0, and a method:

   List<Foo> findByBarIn(@Param("bar") List<Bar> bar);

Spring将此映射到名为/foos/search/findByBarIn的终结点

This gets mapped by Spring to an endpoint called /foos/search/findByBarIn

我可以指定一个类似

获取 http://host/foos/search/findByBarIn?bar = http://host/bars/33 (其中33是Bar实体的ID)

GET http://host/foos/search/findByBarIn?bar=http://host/bars/33 (where 33 is the ID the of the Bar entity)

但是,如何指定多个条形?

But, how can I specify multiple bars?

我尝试过:(没有成功)

I've tried: (with no success)

获取http://host/foos/search/findByBarIn?bar = http://host/bars/33,http://host/bars/44

获取推荐答案

我已经找到了解决方法:

I've found out how to do it:

因此,此原型不起作用:

So, this prototype didn't work:

List<Foo> findByBarIn(@Param("bar") List<Bar> bars);

但是这样做:

List<Foo> findByBarIn(@Param("bar") Bar... bars);

然后,我可以通过以下方式指定多个条形:

And then, I can specify multiple bars by:

GET http://host/foos/search/findByBarIn?bar=http://host/bars/33&bar=http://host/bars/44

这篇关于如何在Spring Data REST导出的端点中使用列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆