1.resultType返回的是封裝的實(shí)體類褐望。返回的字段必須跟實(shí)體類的字段相同,不然有的數(shù)據(jù)會報(bào)空。
<!--根據(jù)類型查詢數(shù)據(jù) -->
<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.實(shí)體類封裝
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;