mapper文件一次空指针异常记录
一个简单的查询,mapper文件的配置如下:
<select id="querySupplierAndDriverId" resultType="com.zhuanche.entity.mdbcarmanage.DriverInfoInterCity"> select driver_id ,city_id ,supplier_id from driver_info_inter_city where driver_id IN <foreach collection="driverIds" open="(" close=")" separator="," item="driverId" > #{driverId} </foreach> AND status = 1 </select>
结果在使用的时候,一直报空指针异常。但是看了下数据库里面也能查询到数据,怎么就空指针了呢?
最后想了下,是这个查询 的结果和resultType的字段没有匹配一块导致的,没有查询出来,按照我的理解,应该是会new 一个对象的,但是应该是没有。先把问题改了
<select id="querySupplierAndDriverId" resultType="com.zhuanche.entity.mdbcarmanage.DriverInfoInterCity"> select driver_id as driverId,city_id as cityId,supplier_id as supplierId from driver_info_inter_city where driver_id IN <foreach collection="driverIds" open="(" close=")" separator="," item="driverId" > #{driverId} </foreach> AND status = 1 </select>
有空研究下源码