【发布时间】:2019-12-02 05:16:53
【问题描述】:
我想获取特定位置附近的所有商店,但查询字符串似乎有问题。我检查了 postgis 的版本是 postgis 2.5.2_2。我还检查了经度和纬度是否具有双精度。
我尝试将查询重写为不同的查询字符串,但仍然出现相同的错误。
我的实体:
@Entity
@Table(name = "seller_geolocation_ms")
public class Seller_Geolocation {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private static final long serialVersionUID = 2L;
private double latitude;
private double longitude;
private String country;
private String cityName;
private String zipCode;
private String town;
private String address;
private Long sellerId;
@JsonIgnore
@Column(columnDefinition = "geometry")
private com.vividsolutions.jts.geom.Point location;
}
我的存储库接口:
@Repository
public interface SellerGeolocationRepository extends CrudRepository<Seller_Geolocation, Long> {
@Query(value="SELECT * FROM seller_geolocation_ms WHERE ST_DWithin(location,?1,?2) = true", nativeQuery = true)
public Set<Seller_Geolocation> findAllSellersInRange(double longitude, double latitude);
}
我的服务类我有这个功能:
public Set<Seller_Geolocation> getAllSellersInLocation(Double longitude, Double latitude) {
return sellerRepository.findAllSellersInRange(longitude, latitude);
}
我收到以下错误:
错误:函数 st_dwithin(几何,双精度,双精度 精度)不存在 提示:没有函数匹配给定的名称和 参数类型。您可能需要添加显式类型转换。
更新:
查询字符串:
SELECT *
FROM seller_geolocation_ms
WHERE ST_DWithin(location::geography, ST_SetSRID(ST_Point(59.393181, 5.286147), 4326), 30000);
在 postgres 数据库中工作,但在 java 应用程序中返回错误:
org.postgresql.util.PSQLException: ERROR: ":" 或附近的语法错误
【问题讨论】:
标签: java postgresql spring-boot postgis