MyBatis Type Handlers for PostGIS
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
- If you are using MyBatis alone, add the type handlers to your
mybatis-config.xml
as follow:
<typeHandlers>
<!-- ... -->
<typeHandler handler="com.eyougo.mybatis.postgis.type.PointTypeHandler" />
<typeHandler handler="com.eyougo.mybatis.postgis.type.PolygonTypeHandler" />
</typeHandlers>
- If you are using MyBatis with Spring, add the type handlers package to the Spring configuration as follow:
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();
}
- If you are using MyBatis with Spring Boot, add the type handlers package to the configuration file as follow:
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".