【发布时间】:2019-07-27 19:58:12
【问题描述】:
我有一个完全工作的服务器,用于提供随机文章,保存在 MySQL 数据库中,我希望能够在多边形内找到文章。
我发现MySQL已经支持Polygon和Point所以我只使用了ST_CONTAINS,它也支持。由于文章确实有嵌入的纬度和经度,我想我可以创建一个点并尝试找出它是否包含在多边形中。
import org.springframework.data.geo.Polygon;
// ...I pass the JPA declaration...
@Query("SELECT an " +
"FROM Announce as an " +
"WHERE ST_CONTAINS(?1, Point(an.latLng.longitude, an.latLng.latitude))")
List<Announce> findAllInPolygon(Polygon polygonPoints);
我没有看到错误,但在运行时出现致命错误:
Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException:
unexpected AST node: ( near line 1, column 80 [SELECT an FROM com.desoftmotion.findnow.domain.Announce
as an WHERE ST_CONTAINS(POLYGON(?1), Point(an.latLng.longitude, an.latLng.latitude))]
我不明白,因为我认为ST_CONTAINS 是已知的。
【问题讨论】:
标签: mysql spring-boot jpa