<分区>
我正在开发一个 Java EE 项目,它具有这样的实体:
@Entity
public class Location {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long messageId;
@ManyToOne
private User user;
private String name;
private Float latitude;
private Float longitude;
}
如果这些位置在 1 公里直径的圆内,我需要用中心点过滤这些位置。
我需要这样的方法,只返回 A、B、C、E 位置。
public List<Location> findLocations(Float longitude, Float latitude) {
List<Location> locations =
entityManager.createQuery("select l from Location where ???")
.setParameter("longitude", longitude)
.setParameter("latitude", latitude)
.getResultList();
return locations;
}
我找到了一些代码示例,但我必须遍历 db 上的所有位置(这将非常昂贵)
我可以直接用 createQuery()
做吗?
Note: I'm using
MySQL