2011-10-15 2 views
2

지리 정보 데이터를 무시하고 MyBatis를 사용하여 PostGIS 데이터베이스에서 데이터를 쿼리하려고합니다. 나는 데이터베이스에 다음과 같은 테이블이 :MyBatis를 사용하여 PostGIS에서 열의 하위 집합을 어떻게 쿼리합니까?

CREATE TABLE salesgeometry 
(
    id bigint NOT NULL, 
    label character varying(255), 
    type character varying(255), 
    geom geometry, 
    CONSTRAINT salesgeometry_pkey PRIMARY KEY (id), 
    CONSTRAINT enforce_dims_geom CHECK (st_ndims(geom) = 2), 
    CONSTRAINT enforce_srid_geom CHECK (st_srid(geom) = 4326) 
) 

내가 MyBatis로이 주석을 사용하여이지도하기 위해 노력하고있어 :

public class Geometry { 
    private long id; 
    private String type; 
    private String label; 
    ... 
} 
이 같은 필드가 있습니다

@Select("SELECT id, type, label FROM salesgeometry WHERE ST_Within(" + 
     "ST_GeomFromText('POINT(#{longitude} #{latitude})', 4326), geom) " + 
     "AND type = #{type}") 
Geometry getGeometryAtLocation(
     @NotNull @Param("type") String geometryType, 
     @NotNull @Param("longitude") BigDecimal longitude, 
     @NotNull @Param("latitude") BigDecimal latitude 
); 

그리고 대상 클래스를

불행히도 이것은 작동하지 않고 대신에

org.postgresql.util.PSQLException: The column index is out of range: 2, number of columns: 1. 

데이터베이스의 열 하위 집합 만 쿼리하는 방법은 무엇입니까?

답변

0

ST_GeomFromText('POINT(#{longitude} #{latitude})', 4326)은 MyBatis에 의해 다음과 같이 준비된 문으로 매핑됩니다. 즉, ST_GeomFromText('POINT(? ?)', 4326)은 물음표가 따옴표 안에 있으므로 예상 매개 변수를 실제로 포함하지 않습니다.

이 솔루션은 ST_GeomFromText('POINT(' || #{longitude} || ' ' || #{latitude} || ')', 4326) 또는 대신 사용하는 문자열 대체 같이 중 하나를 사용 문자열 연결 (하는 것입니다. 준비된 명령문의 매개 변수를 사용하는 대신 직접 SQL 문에 값을 넣습니다 ST_GeomFromText('POINT(${longitude} ${latitude})', 4326),

다음 매핑 작업 (위도와 경도에 대한 2 달러 기호를 적어주십시오) :

@Select("SELECT id, type, label FROM salesgeometry WHERE ST_Within(" + 
     "ST_GeomFromText('POINT(${longitude} ${latitude})', 4326), geom) " + 
     "AND type = #{type}") 
Geometry getGeometryAtLocation(
     @NotNull @Param("type") String geometryType, 
     @NotNull @Param("longitude") BigDecimal longitude, 
     @NotNull @Param("latitude") BigDecimal latitude 
);