本文介绍了Spring JPA存储库如何编写查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个User
类(由id标识)和一个Skills
类,它具有自己的id字段,并且还引用了User
.
I have a User
class, that is identified by id, and Skills
class, that has its own id field, and also references User
.
public class User {
@Id
@GeneratedValue
private int id;
@JsonIgnore
@OneToOne(mappedBy = "user")
private SoftSkills softSkills;
}
另一个有
@Entity
public class SoftSkills {
@Id
@GeneratedValue
private int id;
@OneToOne
@JoinColumn
private User user;
}
是否有一种简单的方法来编写实现JPARepository
的查询,该查询将使用user.id字段作为参数来搜索SoftSkills
类,并返回一个SoftSkills
对象作为结果?
Is there a simple way to write a query, implementing the JPARepository
, that would search the SoftSkills
class by using user.id field as a parameter and return a SoftSkills
object as a result?
推荐答案
您可以从文档中获取:
List<Person> findByAddressZipCode(ZipCode zipCode);
所以这可以解决问题:
SoftSkills findByUserId(int id);
参考; Spring数据JPA文档
这篇关于Spring JPA存储库如何编写查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!