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>
相關文章
相關標籤/搜索