以下代码仅用于演示目的。
My Entity豆看起来像这样
@Entity
class Employee {
@EmbeddedId
private EmployeeKey employeeKey;
private String firstName;
private String lastName;
// Other fields
// Getter and Setters
}
The 可嵌入 class:
@Embeddable
class EmployeeKey implements Serializable {
private int employeeId;
private String branchName;
private String departmentName;
//Getter and Setters
}
我可以写JPA存储库通过 EmbeddedId 查找员工的接口方法也返回结果。
interface EmployeeRepository extends JpaRepository<Employee, EmployeeKey> {
List<Employee> findByEmployeeKey(EmployeeKey employeeKey);
}
问题:假设,在查询时我有员工ID and 分店名称只是,我不想加滤镜部门名称
- 在这种情况下,我该如何编写我的存储库方法
- JPA 是否有针对这种场景的内置功能?
List<Employee> findByEmployeeKeyEmployeeIdAndEmployeeKeyBranchName(
int employId,
String branchName);
应该管用看一下查询派生 http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-property-expressions
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)