table

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

mybatis xml

<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>

写入的时候报错

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

解决办法

<insert id="insert" parameterType="package.model.Test">
    insert into test (id, location)
    values (#{id,jdbcType=INTEGER}, GeomFromText(#{location,jdbcType=OTHER}))
</insert>
12-28 14:59