且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Spring-data-rest 和 Spring-jpa

更新时间:2022-10-14 22:35:23

实际上,我今天只是在研究这个功能.

在最新的快照构建中,有一个新注释:@ConvertWith.你把一个 Spring Core Converter 在该注释中的实现,导出器将使用该转换器将 String[] 查询参数值转换为查询方法的参数.>

有一个 如何在测试中的存储库中使用它的示例(我将很快更新 wiki,但没有机会然而,因为这些新快照上的墨水还没有干:).要在 URL 查询字符串中传递多个值,请多次引用相同的名称:

http://localhost:8080/people/search/findById?id=1&id=2&id=3

当然,您可以选择将多个值编码为单个参数值(例如,逗号分隔)并在您自己的转换器中进行转换.无论如何,您仍然会被传递一个 String[] 到您的自定义转换器.

data-rest and jpa.

I have created one entity with composite keys using @EmbeddedId

and repository extends CrudRepository with findById query param

when I enter the URL

[a link] (http://localhost:8080/data/person/search/findById?findById=1,2&name=abc)

I'm getting error failed to convert string to Long.

Is there any way of converting string to List of Longs using spring JPA?

Please help me.

I was just working on this functionality today, actually.

In the latest snapshot build, there is a new annotation: @ConvertWith. You put the class name of a Spring Core Converter implementation in that annotation and the exporter will use that converter to turn the String[] query parameter values into your query method's parameter.

There is an example of how to use it in your Repository in the tests (I'll update the wiki shortly but haven't had a chance yet as the ink isn't even dry yet on these new snapshots :). To pass multiple values in a URL query string, you reference the same name multiple times:

http://localhost:8080/people/search/findById?id=1&id=2&id=3

You can, of course, chose to encode multiple values into a single parameter value (comma-delimited, for instance) and do the conversion in your own converter. You'll still be passed a String[] to your custom converter no matter what, though.