我尝试使用带有postgres几何类型的JDBI,但得到以下错误:
org.jdbi.v3.core.statement.UnableToCreateStatementException with message:
No argument factory registered for type [com.vividsolutions.jts.geom.Geometry]几何图形是我与.bindBean()绑定的bean的一部分。
我找到了一个相关的question,但答案没有太大帮助。
绑定这种类型的最佳方法是什么?
发布于 2021-09-09 04:53:16
您可以将Jts几何图形转换为geoJson,然后将geoJson绑定为Jdbi中的字符串。
public class GeometryUtils {
private static final GeometryJSON geometryJSON = new GeometryJSON(10);
private static String writeToGeoJson(Geometry geometry) throws IOException {
final var stringWriter = new StringWriter();
geometryJSON.write(geometry, stringWriter);
return stringWriter.toString();
}
}然后假设您的sql查询如下所示
INSERT INTO XYZ(shape) VALUES (st_geomfromgeojson(:shape::jsonb)) 并将shape绑定为GeometryUtils.writeToGeoJson(geom)
https://stackoverflow.com/questions/68934671
复制相似问题