Spring数据页对象json响应没有引用对象信息
我有一个与OwnerGroup实体有FK关系的组织实体Spring数据页对象json响应没有引用对象信息,spring,Spring,我有一个与OwnerGroup实体有FK关系的组织实体 @Entity @Access(AccessType.FIELD) @Table(uniqueConstraints = @UniqueConstraint(columnNames={"appName","appId"})) public class Org { @Id @Column(name = "Id") @GeneratedValue(strategy = GenerationType.IDENTITY)
@Entity
@Access(AccessType.FIELD)
@Table(uniqueConstraints = @UniqueConstraint(columnNames={"appName","appId"}))
public class Org {
@Id
@Column(name = "Id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int Id;
/*@GenericGenerator(name = "sequence_org_id", strategy = "com.ciphercloud.ae.generators.OrgIdGenerator")
@GeneratedValue(generator = "sequence_org_id")
@Column(name="Org_Id")
private String orgId;*/
@NotEmpty (message = "org username is mandatory")
private String username;
@NotEmpty (message = "org password is mandatory")
private String password;
private String securityToken;
@GenericGenerator(name = "sequence_app_id", strategy = "com.ciphercloud.ae.generators.AppIdGenerator")
private String appName;
private String appId;
@NotBlank (message = "Org Category should not be null or empty")
private String orgCategory;
private String orgSubCategory;
@NotBlank (message = "org regionId should not be null or empty")
private String regionId;
@Transient
private int parent_org_id;
@NotFound(action = NotFoundAction.IGNORE)
@ManyToOne
@JsonIgnore
@JoinColumn(name = "parent_org_id")
private Org org;
@NotBlank (message = "Org Type should not be null or empty")
private String orgType;
@Transient
private int ownergroup_id;
@ManyToOne ( cascade = CascadeType.ALL)
@JoinColumn( name = "ownergroup_id")
private OwnerGroup ownerGroup;
我的存储库类看起来像
public interface OrgRepostiory extends JpaRepository<Org, Serializable> {
public List<Org> findByOrgType(@Param("orgtype") String orgType);
public Page<Org> findByOrgTypeIn(@Param("orgtype") List<String> orgType, Pageable pageable);
}
它将获得以下输出
// response
{
username: "testdemo8"
password: "testpwd1"
securityToken: "testkey1"
appName: null
appId: null
orgCategory: "Admin"
orgSubCategory: null
regionId: "na15"
parent_org_id: 0
available: true
inductionStatus: null
orgType: "Production"
ownergroup_id: 0
id: 32
active: false
}-
-
}-
_links: {
self: {
href: "http://localhost:8080/orgs/filter/1?orgtype=Production"
}-
}
不分页
request => http://localhost:8080/orgs/search?orgtype=Production
// response
{
username: "testdemo8"
password: "testpwd1"
securityToken: "testkey1"
appName: null
appId: null
orgCategory: "Admin"
orgSubCategory: null
regionId: "na15"
parent_org_id: 0
available: true
inductionStatus: null
orgType: "Production"
ownergroup_id: 0
**ownerGroup: {
name: "sfdc-ft"
description: "4.5 release"
id: 1
}-**
id: 32
active: false
}
如果我们观察到,当不使用page对象时,它将返回子表数据
但是当我使用分页时,它不会返回子表数据
当我们使用分页时,需要添加什么来获取子表信息吗?我调试了这个问题,发现连接数据正在被控制器类中使用的pagedResourceAssembler类修剪。我换成了 返回新的响应属性>(组织,HttpStatus.OK)
现在它得到了预期的参考对象数据。有人能回答吗???
// response
{
username: "testdemo8"
password: "testpwd1"
securityToken: "testkey1"
appName: null
appId: null
orgCategory: "Admin"
orgSubCategory: null
regionId: "na15"
parent_org_id: 0
available: true
inductionStatus: null
orgType: "Production"
ownergroup_id: 0
id: 32
active: false
}-
-
}-
_links: {
self: {
href: "http://localhost:8080/orgs/filter/1?orgtype=Production"
}-
}
request => http://localhost:8080/orgs/search?orgtype=Production
// response
{
username: "testdemo8"
password: "testpwd1"
securityToken: "testkey1"
appName: null
appId: null
orgCategory: "Admin"
orgSubCategory: null
regionId: "na15"
parent_org_id: 0
available: true
inductionStatus: null
orgType: "Production"
ownergroup_id: 0
**ownerGroup: {
name: "sfdc-ft"
description: "4.5 release"
id: 1
}-**
id: 32
active: false
}