How to map mysql point type in java using mybatis

tablemysql

CREATE TABLE `test` (
  `id` int(11) NOT NULL,
  `location` point DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB

mybatis xmlsql

<resultMap id="BaseResultMap" type="package.model.Test">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="location" jdbcType="OTHER" property="location" />
  </resultMap>
  <insert id="insert" parameterType="package.model.Test">
    insert into test (id, location)
    values (#{id,jdbcType=INTEGER}, #{location,jdbcType=OTHER})
  </insert>

写入的时候报错mybatis

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Cannot get geometry object from data you send to the GEOMETRY field

解决办法code

<insert id="insert" parameterType="package.model.Test">
    insert into test (id, location)
    values (#{id,jdbcType=INTEGER}, GeomFromText(#{location,jdbcType=OTHER}))
</insert>
相关文章
相关标签/搜索