【发布时间】:2016-11-29 07:10:03
【问题描述】:
我使用的是 Spring 1.3.3,我无法使用 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。
- 有没有办法在Employee对象中返回parentId(下一个 名字)?
或
- 是否需要添加投影才能返回 自引用对象?
【问题讨论】:
-
是的,您可以使用投影来内联有关正文中关联的一些信息。
标签: java spring-boot spring-data-rest