【发布时间】:2019-04-15 15:25:42
【问题描述】:
我有一个使用 Spring Data Rest 和 JPA 公开人员资源的非常简单的示例。启动应用程序时,它按预期工作,我可以 POST 和 GET 资源实例。
向 /person 发送 GET 时,我收到以下响应:
"_embedded": {
"person": [
{
"firstName": "FN",
"lastName": "LN",
"_links": {
"self": {
"href": "http://localhost:9090/person/1"
},
"person": {
"href": "http://localhost:9090/person/1"
},
"address": {
"href": "http://localhost:9090/person/1/address"
}
}
}
]
},
"_links": {
"self": {
"href": "http://localhost:9090/person{?page,size,sort}",
"templated": true
},
"profile": {
"href": "http://localhost:9090/profile/person"
},
"search": {
"href": "http://localhost:9090/person/search"
}
},
"page": {
"size": 20,
"totalElements": 1,
"totalPages": 1,
"number": 0
}
}
如您所见,person 资源有一个值为 FN 的 firstName 属性。
我的问题是以下 GET 查询是否应该开箱即用?
/person?firstName=FN
或者这是否需要使用自定义搜索方法来实现?
不用说它不适合我,但我看到关于它是否支持开箱即用的相互矛盾的信息。
提前致谢,
【问题讨论】:
-
您可以使用 Querydsl 实现这一点,请查看以下答案:stackoverflow.com/a/48596145
标签: rest jpa spring-data-rest