Ich arbeite an einem Spring Boot Server basierend auf räumlichen Funktionalitäten.Mybatis Mapper zu Mysql Point Objekt
Und ich bin von der mybatis Übereinstimmung mit benutzerdefinierten Objekt stecken.
Jetzt habe ich eine Tabelle erstellt, und eine Spalte startLocation, die ein Point-Typ ist.
CREATE TABLE `vehicle`.`route` (
`createtime` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
`updatetime` TIMESTAMP NULL,
`startLocation` POINT NULL,
`id` INT(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`));
Und mein Weg Java-Objekt ist
@Table(name = "route")
public class Route extends Base {
Point startLocation;
public Location getStartLocation() {
return startLocation;
}
public void setStartLocation(Location startLocation) {
this.startLocation = startLocation;
}
....other fields
}
Und mein Ort Objekt hält nur lat und lange als den doppelten Wert.
package com.supplyplatform.pojo;
public class Location {
double Lat;
double Long;
public double getLat() {
return Lat;
}
public void setLat(double lat) {
Lat = lat;
}
public double getLong() {
return Long;
}
public void setLong(double l) {
Long = l;
}
}
Mein RouteMapper.xml ist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.supplyplatform.mapper.RouteMapper">
<resultMap type = "com.supplyplatform.pojo.Route" id="Route">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="startpoint" jdbcType="OTHER" property="startLocation" />
</resultMap>
</mapper>
Und es gibt keine typehandler Ausnahme. No typehandler found for property startLocation
Ich habe Tage darauf verbracht. Vielen Dank im Voraus.
UPDATE: Ich versuche, eine Zuordnung zwischen der verschachtelten Ergebniskarte zu erstellen. Die neue XML-Datei ist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.supplyplatform.mapper.RouteMapper">
<select id="selectRoute" resultMap="Route">
SELECT *, X(startpoint) as x, Y(startpoint) as y FROM vehicle.vc_route
</select>
<resultMap type = "com.supplyplatform.pojo.Route" id="Route">
<id column="id" jdbcType="INTEGER" property="id" />
<association property="startLocation" resultMap="Location" />
</resultMap>
<resultMap type = "com.supplyplatform.pojo.Location" id="Location">
<result column="y" property="lat" />
<result column="x" property="long" />
</resultMap>
</mapper>
Aber es zurückgeben immer keine Art Ausnahmebehandler für Location startLocation
.
Ich bin der verschachtelten resultMap Ansatz versucht, aber es gibt immer die No typehandler Ausnahme ich die Frage aktualisiert haben. – Mix
Wählen Sie nicht 'SELECT *', da die Ergebnismenge dann eine Spalte mit dem Namen _startLocation_ enthält und Mybatis versucht, sie (automatisch) der Eigenschaft _startLocation_ zuzuordnen, da der Spaltenname mit dem Eigenschaftsnamen übereinstimmt. – blackwizard
also ist es notwendig, "Location Startpoint" als ein Feld von Route-Objekt? Die Ausnahme wird immer von hier geworfen. – Mix