示例代码:https://github.com/bigben0123/spring-boot-spatial-example

1,配置application.properties

#sqlserver configure
spring.datasource.url =jdbc:sqlserver://localhost:1433;DatabaseName=myDatabase
spring.datasource.username=sa
spring.datasource.password=sa
spring.datasource.driverClassName =com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.database=SQLSERVER
spring.jpa.properties.hibernate.default_schema=dbo

#database name
spring.jpa.properties.hibernate.default_catalog=myDatabase

#使用空间数据类型 geometry等,需要把方言改成:spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServer2008Dialect

# Naming strategy
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy

spring.jpa.hibernate.ddl-auto=create-drop
#spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.h2geodb.GeoDBDialect
#spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.mysql.MySQL56InnoDBSpatialDialect
spring.jpa.show-sql=true
spring.datasource.platform=mysql
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
logging.level.org.hibernate.type=TRACE

2, 在maven中添加sql server的jdbc驱动包

官网下载sqljdbc4的jar包

解压到任意位置(win:E:\sqljdbc_6.0\chs\jre8)。在有sqljdbc4.jar包的文件夹下,通过shift+右键的方式–>此处打开命令窗口,然后执行以下maven命令: 

mvn install:install-file -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.2 -Dpackaging=jar -Dfile=E:\sqljdbc_6.0\chs\jre8\sqljdbc42.jar

显示build success,mvn库文件会放在C:\UsersAdministrator\.m2\repository\com\microsoft\sqlserver

3,pom.xml中添加依赖

<!-- sqlserver connector -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<scope>4.2</scope>
<version>4.2</version>
</dependency>

 ____________________________________________________________________________________________________

源码参考:

super entity:

package org.vaadin.example;

import java.io.Serializable;
import java.util.Objects;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

/**
 *
 * @author Matti Tahvonen
 */
@MappedSuperclass
public abstract class AbstractEntity implements Serializable, Cloneable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Version
    private int version;

    public Long getId() {
        return id;
    }

    protected void setId(Long id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if(this.id == null) {
            return false;
        }

        if (obj instanceof AbstractEntity && obj.getClass().equals(getClass())) {
            return this.id.equals(((AbstractEntity) obj).id);
        }

        return false;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 43 * hash + Objects.hashCode(this.id);
        return hash;
    }
    
}
View Code

相关文章:

  • 2022-12-23
  • 2021-04-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-07
  • 2022-12-23
猜你喜欢
  • 2021-05-07
  • 2021-11-22
  • 2022-12-23
  • 2022-01-06
  • 2021-11-11
相关资源
相似解决方案