1
我有一個與OwnerGroup實體具有FK關係的組織實體。Spring數據頁面對象沒有引用對象的JSON響應信息
@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);
}
我有一個控制器類,將它們公開爲REST和代碼是
@RequestMapping(value = "/search", method = RequestMethod.GET)
public ResponseEntity<List<Org>> testmap(@RequestParam MultiValueMap<String, String> params) {
System.out.println("params........" + params);
List<Org> orgs = orgServiceImpl.search(params);
if (orgs == null || orgs.size()==0) {
throw new ResourceNotFoundException("Invalid search criteria ");
} else {
return new ResponseEntity<List<Org>>(orgs, HttpStatus.OK);
}
}
@RequestMapping(value = "/filter/{pageNumber}", method = RequestMethod.GET)
public ResponseEntity<PagedResources<org.springframework.hateoas.Resource<Org>>> filter(@PathVariable Integer pageNumber, @RequestParam HashMap<String, List<String>> params) {
System.out.println("params........" + params);
if(pageNumber <= 0){
pageNumber = 1;
}
Page<Org> orgs = orgServiceImpl.filter(pageNumber, params);
if (orgs == null || orgs.getSize()==0) {
throw new ResourceNotFoundException("Invalid filter criteria ");
} else {
return new ResponseEntity<>(pagedResourceAssembler.toResource(orgs), HttpStatus.OK);
}
}
現在,當我測試的REST客戶端請求爲
request = > http://localhost:8080/orgs/filter/1?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
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
}
如果我們觀察到,當不使用頁面對象,其返回子表中的數據。
但是當我使用分頁時,它不會返回子表數據。
當我們使用分頁時,是否需要添加任何東西來獲取子表信息?
可以任何一個請回答??? –