确认
当前程序版本
3.5.10.1
问题描述
我的情况是这样的,一共有四个类,Order
Address
Waste
和WastePhoto
各类的代码
Order类
@Data
@TableName("orders")
@AllArgsConstructor
@NoArgsConstructor
public class Order implements Serializable {
@TableId(type = IdType.AUTO)
private Long id;
private Long userId;
@TableField(exist = false)
private Waste waste;
@TableField(exist = false)
private Address address;
private LocalDateTime orderDate;
private Integer orderStatus;
private BigDecimal estimatedPrice;
private BigDecimal actualPrice;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private Integer isDeleted;
private Long addressId;
private Long wasteId;
}
Waste类
@Data
@TableName("wastes")
public class Waste implements Serializable {
@TableId(type = IdType.AUTO)
private Long id;
private Integer type;
private String name;
private Double weight;
private Integer unit;
private String description;
@TableField(exist = false)
private List<WastePhoto> photos;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
}
Address类
@Data
@TableName("addresses")
public class Address implements Serializable {
@TableId(type = IdType.AUTO)
private Long id;
private String name;
private String phoneNum;
private String province;
private String city;
private String area;
private String detail;
private String pickupTime;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
}
WastePhoto类
@Data
@Builder
@TableName("waste_photos")
public class WastePhoto implements Serializable {
@TableId(type = IdType.AUTO)
private Long id;
private Long wasteId;
private String imagePath;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
}
以及OrderMapper的代码
<?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.bryan.mybatisplus_demo.mapper.OrderMapper">
<resultMap id="AddressResultMap" type="com.bryan.mybatisplus_demo.entity.Address">
<id column="address_id" property="id"/>
<result column="address_name" property="name"/>
<result column="address_phoneNum" property="phoneNum"/>
<result column="address_province" property="province"/>
<result column="address_city" property="city"/>
<result column="address_area" property="area"/>
<result column="address_detail" property="detail"/>
<result column="address_pickupTime" property="pickupTime"/>
</resultMap>
<resultMap id="WastePhotoResultMap" type="com.bryan.mybatisplus_demo.entity.WastePhoto">
<id column="waste_photo_id" property="id"/>
<result column="waste_photo_waste_id" property="wasteId"/>
<result column="waste_photo_image_path" property="imagePath"/>
<result column="waste_photo_created_at" property="createdAt"/>
<result column="waste_photo_updated_at" property="updatedAt"/>
</resultMap>
<resultMap id="WasteResultMap" type="com.bryan.mybatisplus_demo.entity.Waste">
<id column="waste_id" property="id"/>
<result column="waste_type" property="type"/>
<result column="waste_name" property="name"/>
<result column="waste_weight" property="weight"/>
<result column="waste_unit" property="unit"/>
<result column="waste_description" property="description"/>
<collection property="photos"
ofType="com.bryan.mybatisplus_demo.entity.WastePhoto"
resultMap="WastePhotoResultMap"/>
</resultMap>
<resultMap id="OrderResultMap" type="com.bryan.mybatisplus_demo.entity.Order">
<id column="id" property="id"/>
<result column="userId" property="userId"/>
<result column="orderDate" property="orderDate"/>
<result column="orderStatus" property="orderStatus"/>
<result column="estimatedPrice" property="estimatedPrice"/>
<result column="actualPrice" property="actualPrice"/>
<result column="createdAt" property="createdAt"/>
<result column="updatedAt" property="updatedAt"/>
<association property="address"
javaType="com.bryan.mybatisplus_demo.entity.Address"
resultMap="AddressResultMap"/>
<association property="waste"
javaType="com.bryan.mybatisplus_demo.entity.Waste"
resultMap="WasteResultMap"/>
</resultMap>
<sql id="sql_base">
SELECT o.id AS id,
o.user_id AS userId,
o.order_date AS orderDate,
o.order_status AS orderStatus,
o.estimated_price AS estimatedPrice,
o.actual_price AS actualPrice,
o.created_at AS createdAt,
o.updated_at AS updatedAt,
a.id AS address_id,
a.name AS address_name,
a.phone_num AS address_phoneNum,
a.province AS address_province,
a.city AS address_city,
a.area AS address_area,
a.detail AS address_detail,
a.pickup_time AS address_pickupTime,
w.id AS waste_id,
w.type AS waste_type,
w.name AS waste_name,
w.weight AS waste_weight,
w.unit AS waste_unit,
w.description AS waste_description,
wp.id AS waste_photo_id,
wp.waste_id AS waste_photo_waste_id,
wp.image_path AS waste_photo_image_path,
wp.created_at AS waste_photo_created_at,
wp.updated_at AS waste_photo_updated_at
FROM orders o
JOIN addresses a ON o.address_id = a.id
JOIN wastes w ON o.waste_id = w.id
LEFT JOIN waste_photos wp ON w.id = wp.waste_id
</sql>
<select id="findByPage" parameterType="map" resultMap="OrderResultMap">
<include refid="sql_base"/>
WHERE o.user_id = #{userId} AND o.is_deleted = 0
ORDER BY o.order_date DESC
</select>
</mapper>
当我调用findByPage查询时,一直报错
org.springframework.jdbc.UncategorizedSQLException: Error attempting to get column 'orderStatus' from result set. Cause: java.sql.SQLException: Type class java.time.LocalDateTime not supported type for TINYINT type
; uncategorized SQLException; SQL state [null]; error code [0]; Type class java.time.LocalDateTime not supported type for TINYINT type
但问题是Order类的orderStatus就是Integer类,不清楚为什么会识别成LocalDateTime类。
如果改成二次查询就没有问题
OrderMapper.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.bryan.mybatisplus_demo.mapper.OrderMapper">
<resultMap id="AddressResultMap" type="com.bryan.mybatisplus_demo.entity.Address">
<id column="address_id" property="id"/>
<result column="address_name" property="name"/>
<result column="address_phoneNum" property="phoneNum"/>
<result column="address_province" property="province"/>
<result column="address_city" property="city"/>
<result column="address_area" property="area"/>
<result column="address_detail" property="detail"/>
<result column="address_pickupTime" property="pickupTime"/>
</resultMap>
<resultMap id="WasteResultMap" type="com.bryan.mybatisplus_demo.entity.Waste">
<id column="waste_id" property="id"/>
<result column="waste_type" property="type"/>
<result column="waste_name" property="name"/>
<result column="waste_weight" property="weight"/>
<result column="waste_unit" property="unit"/>
<result column="waste_description" property="description"/>
<collection property="photos"
ofType="com.bryan.mybatisplus_demo.entity.WastePhoto"
select="com.bryan.mybatisplus_demo.mapper.WastePhotoMapper.selectByWasteId"
column="waste_id"/>
</resultMap>
<resultMap id="OrderResultMap" type="com.bryan.mybatisplus_demo.entity.Order">
<id column="id" property="id"/>
<result column="userId" property="userId"/>
<result column="orderDate" property="orderDate"/>
<result column="orderStatus" property="orderStatus"/>
<result column="estimatedPrice" property="estimatedPrice"/>
<result column="actualPrice" property="actualPrice"/>
<result column="createdAt" property="createdAt"/>
<result column="updatedAt" property="updatedAt"/>
<association property="address"
javaType="com.bryan.mybatisplus_demo.entity.Address"
resultMap="AddressResultMap"/>
<association property="waste"
javaType="com.bryan.mybatisplus_demo.entity.Waste"
resultMap="WasteResultMap"/>
</resultMap>
<sql id="sql_base">
SELECT o.id AS id,
o.user_id AS userId,
o.order_date AS orderDate,
o.order_status AS orderStatus,
o.estimated_price AS estimatedPrice,
o.actual_price AS actualPrice,
o.created_at AS createdAt,
o.updated_at AS updatedAt,
a.id AS address_id,
a.name AS address_name,
a.phone_num AS address_phoneNum,
a.province AS address_province,
a.city AS address_city,
a.area AS address_area,
a.detail AS address_detail,
a.pickup_time AS address_pickupTime,
w.id AS waste_id,
w.type AS waste_type,
w.name AS waste_name,
w.weight AS waste_weight,
w.unit AS waste_unit,
w.description AS waste_description
FROM orders o
JOIN
addresses a ON o.address_id = a.id
JOIN
wastes w ON o.waste_id = w.id
</sql>
<select id="findByPage" parameterType="map" resultMap="OrderResultMap">
<include refid="sql_base"/>
WHERE o.user_id = #{userId} AND o.is_deleted = 0
ORDER BY o.order_date DESC
</select>
</mapper>
WastePhotoMapper.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.bryan.mybatisplus_demo.mapper.WastePhotoMapper">
<!-- 根据废弃物ID查询废弃物图片 -->
<select id="selectByWasteId" resultType="com.bryan.mybatisplus_demo.entity.WastePhoto"
parameterType="long">
SELECT id, waste_id, image_path, created_at, updated_at
FROM waste_photos
WHERE waste_id = #{wasteId}
</select>
</mapper>
这个是我编写的最小的复线项目:mybatisplus_demo.zip
详细堆栈日志
Comment From: miemieYaho
复现demo请提交到git仓库再给出地址
Comment From: Bryan2333
复现demo仓库:https://github.com/Bryan2333/mybatisplus_demo
Comment From: miemieYaho
你只用mybatis去除掉mp就不报错吗?
Comment From: Bryan2333
没事了,lombok的问题,WastePhoto类上面有个Builder注解,把这个注解去掉后,就没有报错了。
Comment From: Shin-God
感谢老哥,被困扰了一整天,压根没想到是@Builder的问题。。。