【发布时间】:2019-07-28 08:46:37
【问题描述】:
我的 JPA 休息项目遇到了一些困难。 我已经为我的每个实体(我的数据库中的表)构建了我的存储库,并且工作正常。 例如,我的实体“Personne”的一部分:
@Entity
public class Personne {
private Long id;
private String nom;
private String prenom;
private Date dateNaissance;
private String telDomicile;
private String telPortable;
private String telAutre;
private String telCommentaire;
private String fax;
private String mail;
private String commentaire;
private Timestamp dateSuppr;
private String sexe;
private Patient patientById;
private Adresse adresseByAdresseId;
@Id
@JsonProperty(value = "dataId")
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
还有带有 @Query 的 myRepository :
@Transactional
@RepositoryRestResource(collectionResourceRel = "personne", path = "personne", excerptProjection = InlinePersonne.class)
public interface PersonneRepo extends JpaRepository<Personne, Long> {
@Query("from Personne p where p.nom = ?1 and p.prenom = ?2")
public Personne customRequest(String nom, String prenom);
}
我的问题:返回结果始终是“Personne”类型。
我想发出一个本机请求,将带有自定义属性的对象发回给我。
期望回报的例子:
{object :
{name : String,
surname : String,
age : int },
adresse :{
city : String,
street : String
}
}
有可能这样做吗? 我真的需要它,因为我必须在许多表上提出复杂的请求。 谢谢。
【问题讨论】:
标签: rest spring-boot jpa repository