Ich habe eine Org-Entität, die FK-Beziehung mit OwnerGroup-Einheit hat.Frühling Daten Seite Objekt JSON Antwort nicht Referenz Objekt Info
@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;
Meine Repository-Klasse sieht aus wie
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);
}
Ich habe eine Controller-Klasse, sie als REST zu entlarven und der Code ist als
@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);
}
}
Nun, wenn ich den Antrag in Rest-Client testen für die
request = > http://localhost:8080/orgs/filter/1?orgtype=Production
Es erhält die folgende Ausgabe.
// 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"
}-
}
ohne Paginierung
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
}
Wenn wir beobachten, wenn Seitenobjekt nicht verwendet wird, ist es das Kind Tabellendaten zurück.
Aber wenn ich Paginierung verwenden, gibt es die untergeordneten Tabellendaten nicht zurück.
Muss etwas hinzugefügt werden, um die untergeordneten Tabelleninformationen zu erhalten, wenn wir Paging verwenden?
kann jemand bitte antworten ??? –