我有位置,我想要按公司
检索数据库中的所有位置我可以这样做List<Location> findByCompanyId(Long companyId);
但我如何检索地点的ID而不是整个对象
List<Long> findByCompanyId(Long companyId);
我想要与第一种方法相同的东西,但没有整个对象只有ids
public class Location extends BaseEntity {
@Column(name = "`street_first`", nullable = false)
private String streetFirst;
@Column(name = "`street_second`")
private String streetSecond;
@Column(name = "`city`", nullable = false)
private String city;
@Column(name = "`zip`")
private String zip;
@Column(name = "`state`", nullable = false)
private String state;
@Column(name = "`phone`", nullable = false)
private String phone;
@JoinColumn(name = "`company_id`", nullable = false)
private Company company;
}
//getters and setters
答案 0 :(得分:1)
@Query("SELECT l.id FROM Location l WHERE l.company.id = :companyId");
List<Long> getLocationIds(@Param("companyId")Long companyId);