本文在deepin中测试过,windows版本的配置看–这里。
mvn install:install-file -Dfile=spatialite-jdbc-4.3.0a.jar -DgroupId=org.hdm -DartifactId=spatialite-jdbc -Dversion=4.3.0a -Dpackaging=jar --settings /xxx/Maven/settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
...
<dependencies>
...
<dependency>
<groupId>org.hdm</groupId>
<artifactId>spatialite-jdbc</artifactId>
<version>4.3.0a</version>
</dependency>
...
</dependencies>
...
</project>
原来想在application.properties文件里写配置文件的,可不知如何配置connectionProperties,故作罢,有知道的小伙伴欢迎留言。
spring.datasource.driver-class-name=org.spatialite.JDBC
spring.datasource.url=jdbc:spatialite::resource:static/db/sqlitegdb.sqlite3
spring.datasource.connectionProperties=enable_shared_cache=true;enable_load_extension=true;enable_spatialite=true
因此在application.properties文件里写数据库连接信息,创建DataSourceConfig类进行配置。
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import javax.sql.DataSource;
@Configuration
public class DataSourceConfig {
@Autowired
private Environment env;
@Bean
public DataSource getDataSource()
{
DruidDataSource dataSourceBuilder = new DruidDataSource();
dataSourceBuilder.setDriverClassName(env.getProperty("spring.datasource.driver-class-name"));
dataSourceBuilder.setUrl(env.getProperty("spring.datasource.url"));
dataSourceBuilder.setConnectionProperties(env.getProperty("spring.datasource.connectionProperties"));
return dataSourceBuilder;
}
}
//DaoMapper.xml
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="ObjectDao">
<select id="findGeo" resultType="Object">
select AsText(ST_Transform(MakePoint(114.1689,22.4518,4326),3857));
</select>
</mapper>
{
"results": [
"POINT(12709223.812428 2565856.375115)"
]
}