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

霸气de小男生 提交于 2019-12-06 09:47:38

问题


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:


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.



来源:https://stackoverflow.com/questions/11851645/spring-data-rest-and-spring-jpa

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