0
点赞
收藏
分享

微信扫一扫

智慧安防边缘计算硬件AI智能分析网关V4算法启停的操作步骤

狗啃月亮_Rachel 2024-04-27 阅读 8

mybatis映射postgres数据库的geometry类型

文章目录

一、问题背景和需求描述

  1. 前端保存的geometry数据类型是json格式({“type”:“Point”,“coordinates”:[119.9556356,30.5469975]}类似)
  2. 数据库存储数据是16进制(经过st_geomfromgeojson(json)函数转换之后再存储的数据 01010000002C39382229FD5D40677E3507088C3E40)
  3. 后端java对象用string接口,需要再存储之前将json转16进制对象后再存储
  4. 查询时需要16进制数据转成json,返回前端

二、解决步骤

  1. 导入java类型转换需要的包
  2. 自定义mybatis类型转换器(GeometryTypeHandler)
  3. 注册类型转换器
  4. 再实体类添加类型转换器注解

1、导入java类型转换需要的包

        <dependency>
            <groupId>net.postgis</groupId>
            <artifactId>postgis-jdbc</artifactId>
            <version>2023.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-geojson</artifactId>
            <version>${geotools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-main</artifactId>
            <version>${geotools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-opengis</artifactId>
            <version>${geotools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            
举报

相关推荐

0 条评论