1.resultType返回的是封装的实体类。返回的字段必须跟实体类的字段相同,不然有的数据会报空。
<!--根据类型查询数据 -->
<select id="findDeviceStatus" resultType="com.kldhq.weight.entity.CarGpsAlarmAndCar">
SELECT
cga.id,
cga.device_number AS deviceNumber,
cga.gps_time AS gpsTime,
cga.latitude,
cga.longitude,
cga.speed,
cga.status,
cga.mileage,
cga.direction,
cga.device_status,
cga.is_read AS isRead,
cga.alarm_type AS alarmType,
c.id AS Carid,
c.car_number AS carNumber,
c.driver,
c.phone,
c.color,
c.gps_device_number AS gpsDeviceNumber
FROM
car_gps_alarm AS cga INNER JOIN
car AS c ON cga.device_number = c.gps_device_number
<where>
<if test="alarmType !=null and alarmType !=''">
and cga.alarm_type = #{alarmType}
</if>
<if test="gpsDeviceNumber !=null and gpsDeviceNumber !=''">
and cga.device_number = #{gpsDeviceNumber}
</if>
</where>
</select>
2.实体类封装
public class CarGpsAlarmAndCar {
private Integer id;
private String deviceNumber;
private Date gpsTime;
private Double latitude;
private Double longitude;
private Integer speed;
private String status;
private Double mileage;
private String direction;
private String deviceStatus;
private Integer isRead;
private String alarmType;
private Integer Carid;
private String carNumber;
private String driver;
private String phone;
private String color;
private String gpsDeviceNumber;