1,所需jar包maven依賴
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>5.2.10.Final</version>
</dependency>
<dependency>
<groupId>org.geolatte</groupId>
<artifactId>geolatte-geom</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>com.vividsolutions</groupId>
<artifactId>jts</artifactId>
<version>1.13</version>
</dependency>
注意:
hibernate-spatial依賴下載不下了,通過手動下載的方式然後再上傳到私服進行引用。
2,jpa配置信息
spring:
datasource:
url: jdbc:postgresql://10.7.15.2:5432/SSHZQ_DATA1?useSSL=false
username: postgress
password: gtisa
jpa:
hibernate:
ddl-auto: update
show-sql: true
properties.hibernate.jdbc.lob.non_contextual_creation: true
3,實體創建
@Entity
@Table(name = "jc_jzwa")
@Getter
@Setter
public class JcjzwaEntity implements Serializable {
@Id
@Column(name = "smid")
private Integer smid;
}
此表是數據庫中已有的表,id字段必須指定。
4,dao層編寫
public interface JcjzwaAnalysisRepo extends JpaRepository<JcjzwaEntity, Integer> {
String sqlStr = "select st_astext(smgeometry), Smid, bldman from jc_jzwa where smid < 10";
@Query(nativeQuery=true, value = sqlStr)
List<Map> aa();
}
這邊使用原生的sql進行查詢,通過Map對象來接收結果。