在spring-boot中,我有两个实体:
package interv.Entities;
import com.fasterxml.jackson.annotation.JsonBackReference;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Intervention implements Serializable {
@Id @GeneratedValue
private Long Id;
private String objet;
@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date date;
@Column(columnDefinition="BOOLEAN DEFAULT false")
private boolean valid;
@ManyToOne
@JoinColumn(name="id_Project")
@JsonBackReference(value="projet-intervention")
private Project project;
@ManyToOne
@JoinColumn(name = "Id_AppUser")
@JsonBackReference(value="appuser-intervention")
private AppUser appUser;
@ManyToOne
@JoinColumn(name ="Id_AppDevlopper")
@JsonBackReference(value="appuser-intervention-devlopper")
private AppUser app ;
}
也为项目实体:
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Project implements Serializable{
@Id @GeneratedValue
private long id;
private String intitule;
private String description;
@ManyToOne
@JoinColumn(name = "Id_appUser")
@JsonBackReference(value="projet-appuser")
private AppUser appUser;
@OneToMany(mappedBy = "project")
@Fetch(value=FetchMode.SUBSELECT)
@JsonManagedReference(value="projet-intervention")
private Collection<Intervention> interventions = new ArrayList<Intervention>();
public void addToIntervention(Intervention intervention) { this.interventions.add(intervention);}
}
在angular5中,我正在尝试通过spring的rest控制器获取特定用户的干预页面:
@Query("select i from Intervention i where i.appUser = :userApp")
public Page<Intervention> interventionsOfClient(@Param("userApp") AppUser userApp , Pageable pageable);
其余控制器:
@RequestMapping(value="clientsintervention",method= RequestMethod.GET)
public Page<Intervention> getClientsIntervention(
@RequestParam(name="page",defaultValue = "0") int page,
@RequestParam(name="size",defaultValue = "5") int size,
@RequestParam(name="id",defaultValue ="0") Long id
){
AppUser appUser = userRepo.getOne(id);
return interventionRepo.interventionsOfClient(appUser,new PageRequest(page,size));
}
此方法返回一个干预页面,每个干预都包含{id,object,date,valid},并且没有我期望的对象Project,并且我不想在我的前端页面中使用它。
关于如何解决该问题的任何想法?