我有一个postgres表Alpha
,它有一个名为geom
的列,类型为geography
。我想通过mybatis xml查询将数据插入此列,但在运行插入查询时收到以下错误。
### Cause: org.postgresql.util.PSQLException: ERROR: syntax error at or near "'POINT(49.9469 41.7325)'"
Position: 1077
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:199)
由于mybatis没有提供良好的错误日志,所以我不确定mybatis xml查询的错误是什么。
table-
CREATE TABLE ALPHA (
geom georaphy(point, 4326)
);
我写的查询-
<insert id="save">
INSERT INTO ALPHA (
geom)
VALUES (
'POINT(${input.longitude} ${input.latitude})'
);
</insert>
输入类型如下-
public class Input {
private Double latitude;
private Double longitude;
}
我也试过,但这次也失败了-
<insert id="save">
INSERT INTO ALPHA (
geom)
VALUES (
'POINT(#{input.longitude} #{input.latitude})'
);
</insert>
1条答案
按热度按时间nhaq1z211#
如果您使用Postgis,这个TypeHandler可以帮助您。您pojo字段类型必须是JTS几何图形。