![](/img/trans.png)
[英]How to fetch embeddedId object in GET call using Spring Data Rest
[英]How to fetch Self Referencing object in GET call using Spring Data Rest
我正在使用Spring 1.3.3,並且即使它不為null,也無法使用GET在Spring Data Rest Response中獲取自引用對象。
例如
我的桌子:
CREATE TABLE `employee` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(40) NOT NULL,
`parent_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`),
KEY `FK_employee_parent` (`parent_id`),
CONSTRAINT `FK_employee_parent` FOREIGN KEY (`parent_id`) REFERENCES `employee` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8057 DEFAULT CHARSET=latin1
響應:
{
"id": 1,
"name": "Test Employee",
"_links": {
"self": {
"href": "http://localhost:8081/employee/1"
},
"employee": {
"href": "http://localhost:8081/employee/1"
},
"parent": {
"href": "http://localhost:8081/employee/1/parent"
}
}
}
但是我需要名稱字段旁邊的parent_id,而不是在“ links ”下。
要么
我建議在春季休息時使用傑克遜。 然后,您可以輕松地將注釋添加到域對象,以重命名指向parent_id的鏈接。
@JsonProperty("parent_id")
您還需要在類上方添加兩個注釋
@JsonSerialize
@JsonInclude
最佳實踐實際上不是直接使用域對象,而是在兩者之間使用pojo處理該對象。 因此,然后將域對象數據復制到該pojo,您將僅在其余響應中顯示要顯示的內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.