Java Mybatis:创建bean时出错,未找到属性的类型处理程序
我要映射的对象路径: Route.java:Java Mybatis:创建bean时出错,未找到属性的类型处理程序,java,spring,mybatis,Java,Spring,Mybatis,我要映射的对象路径: Route.java: package com.supplyplatform.pojo; import java.util.Date; import javax.persistence.Column; import javax.persistence.Table; import org.springframework.format.annotation.DateTimeFormat; @Table(name = "vc_route") public class Ro
package com.supplyplatform.pojo;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Table;
import org.springframework.format.annotation.DateTimeFormat;
@Table(name = "vc_route")
public class Route extends Base {
private Location startLocation;
public Location getStartLocation() {
return startLocation;
}
public void setStartLocation(Location startLocation) {
this.startLocation = startLocation;
}
...other fields
}
Location.java:
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;
}
}
RouteMapper.xml:
<?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 id,
car_id as carid,
driver_id as driverid,
cost_id as costid,
order_id as orderid,
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>
我想知道Spring是否会干扰Route类中的javax.persistence注释。如果您没有使用JPA,则不应该需要它们。如果删除它们会发生什么情况?嗯,刚刚尝试了这个,但仍然抛出异常可能会让您更接近初始问题的解决方案。虽然属性是通过getter/setter访问的,但将属性Lat/Long重命名为latitude/longitude(小写首字母)以及它们的getter/setter,并将其作为结果映射。为了消除疑问(无论如何,这是最佳做法),如果在“选择”中用resultType=“map”替换resultMap,查询将返回
列表
,请在调试断点时检查自动映射的类型。
Error creating bean with name 'routeMapper' defined in file [D:\workspace\vehicle\target\classes\com\supplyplatform\mapper\RouteMapper.class]: Invocation of init method failed;
nested exception is java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalStateException: No typehandler found for property startLocation