【发布时间】:2021-07-06 20:30:55
【问题描述】:
我有这个实体:
@Entity
@Data
@NoArgsConstructor
@Table(name = "employees")
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "employee_id")
private Long id;
private String firstName;
private String lastName;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name = "manager_id")
private Employee manager;
}
有对应的仓库:
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
// ..
}
当我发出GET 请求以通过id 查找员工时,我得到以下结果:
{
"firstName":"Steven",
"lastName":"King",
"_links":{
"self":{
"href":"http://localhost:8081/api/employees/100"
},
"employee":{
"href":"http://localhost:8081/api/employees/100"
},
"manager":{
"href":"http://localhost:8081/api/employees/100/manager"
}
}
}
http://localhost:8081/api/employees/100/manager 不能与 Lazy fetching 一起使用,那么我该如何将其更改为:http://localhost:8081/api/employees/99 其中 99 是 @ 987654329@史蒂文的经理?
【问题讨论】:
标签: spring spring-boot spring-data-jpa spring-data-rest