Spring-data-rest and Spring-jpa [closed]

2020-07-26 11:20发布

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.

1条回答
贼婆χ
2楼-- · 2020-07-26 12:09

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.

查看更多
登录 后发表回答