Spring-data-rest 和 Spring-jpa [英] Spring-data-rest and Spring-jpa

查看:46
本文介绍了Spring-data-rest 和 Spring-jpa的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

data-rest 和 jpa.

我使用@EmbeddedId 创建了一个带有复合键的实体

和存储库使用 findById 查询参数扩展 CrudRepository

当我输入网址时

[一个链接] (http://localhost:8080/data/person/search/findById?findById=1,2&name=abc)

我收到错误,无法将字符串转换为 Long.

有没有什么办法可以使用 spring JPA 将字符串转换为多头列表?

请帮帮我.

解决方案

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

在最新的快照构建中,有一个新注释:@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.

这篇关于Spring-data-rest 和 Spring-jpa的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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