首先将要将resultMap 里面的类都排查一下,是否将colum和property混乱了,colum是表查出的数据,property是类的数据,确认无误后,便排查下面的select。
这次问题的发生原因是,select里面的resultMap写错了,写成了resultType。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org/DTD Mapper 3.0" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bocom.mapper.CustomerMapper">
<resultMap id="BaseResultMap" type="com.bocom.vo.VipCustomerVO">
<id column="ID" property="id"/>
<result column="CUSTOMER_ID" property="customerId" />
<result column="CUSTOMER_NAME" property="customerName" />
<result column="STAFF_ID" property="staffId" />
<result column="no_vip" property="noVip" />
</resultMap>
<select id="queryListByStaffId" resultType="BaseResultMap">
SELECT a.id, a.CUSTOMER_ID, a.CUSTOMER_NAME, a.STAFF_ID, ISNULL(b.customer_id) AS no_vip
FROM customers a
LEFT JOIN (SELECT * FROM app_vip_customer WHERE staff_id = #{staffId}) b
ON a.CUSTOMER_ID = b.CUSTOMER_ID
</select>
</mapper>
修改完后,如下可以正常运行。
<select id="queryListByStaffId" resultMap="BaseResultMap">