MyBatis Type Handlers for PostGIS

Build Status Maven central

The MyBatis type handlers supporting geometry types introduced in PostGIS: JDBC Geometry API

Requirements

Java 7 or higher.

The latest PostGIS JDBC API which it depends on was using the JRE7 version of PostgreSQL JDBC, so it requires Java 7 or higher.

Installation

If you are using Maven add the following dependency to your pom.xml:

<dependency>
    <groupId>com.eyougo</groupId>
    <artifactId>mybatis-typehandlers-postgis</artifactId>
    <version>1.0</version>
</dependency>

Configuration

<typeHandlers>
    <!-- ... -->
    <typeHandler handler="com.eyougo.mybatis.postgis.type.PointTypeHandler" />
    <typeHandler handler="com.eyougo.mybatis.postgis.type.PolygonTypeHandler" />
</typeHandlers>

With XML Configuration

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <!-- ... -->
    <property name="typeAliasesPackage" value="com.eyougo.mybatis.postgis.type" />
</bean>

Or with Java configuration

@Bean
public SqlSessionFactory sqlSessionFactory(Configuration config) {
    SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
    // ...
    factory.setTypeHandlersPackage("com.eyougo.mybatis.postgis.type");
    return factory.getObject();
}

application.properties

mybatis.type-handlers-package = com.eyougo.mybatis.postgis.type

Or application.yml

mybatis:
    type-handlers-package: com.eyougo.mybatis.postgis.type

Supported types

The following type handlers are supported:

Type handler PostGIS Geometry API type Available version
PointTypeHandler org.postgis.Point 1.0
PolygonTypeHandler org.postgis.Polygon 1.0
LineStringTypeHandler org.postgis.LineString 1.0
MultiPointTypeHandler org.postgis.MultiPoint 1.0

Note: For more details of type handler, please refer to "MyBatis 3 REFERENCE DOCUMENTATION".