如何使用mybatis在java中映射mysql點類型?現在是java.lang.Object。 這是我的表:如何在java中使用mybatis映射mysql點類型
CREATE TABLE `test` (
`id` int(11) NOT NULL,
`location` point DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
這是發電機給出的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>
我曾嘗試:
public void testPointType() {
GeometryFactory geometryFactory = new GeometryFactory();
com.vividsolutions.jts.geom.Point point = geometryFactory.createPoint(new Coordinate(1, 1));
package.model.Test record = new package.model.Test();
record.setLocation(point.toText());
testMapper.insertSelective(record);
}
但得到:com.mysql.jdbc.MysqlDataTruncation: Data truncation: Cannot get geometry object from data you send to the GEOMETRY field
以及如何選擇? – Tiina
@Tiina更新回答,請檢查它。 – Blank
這是一種方法。 – Tiina