以下代码仅用于演示目的。
我的实体bean看起来像这样
@Entity
class Employee {
@EmbeddedId
private EmployeeKey employeeKey;
private String firstName;
private String lastName;
// Other fields
// Getter and Setters
}
可嵌入类:
@Embeddable
class EmployeeKey implements Serializable {
private int employeeId;
private String branchName;
private String departmentName;
//Getter and Setters
}
我可以编写JPARepository接口(interface)方法来通过EmbeddedId查找雇员,该方法也返回我的结果。
interface EmployeeRepository extends JpaRepository<Employee, EmployeeKey> {
List<Employee> findByEmployeeKey(EmployeeKey employeeKey);
}
问题:
假设在查询时,我只有employeeId和branchName,并且我不想在departmentName上放置过滤器
最佳答案
List<Employee> findByEmployeeKeyEmployeeIdAndEmployeeKeyDepartmentName(int Id,String name);
应该工作Have a look at query derivation