日期:2014-05-18  浏览次数:20624 次

ibatis多表查询问题
本帖最后由 Bactryki28 于 2014-04-23 15:20:17 编辑
我要进行一项查询是需要将两张表的数据拼凑成一个对象
VO类如下:A.java
private String id;
private String deviceId;
private String plate;
private String plateTypeCode;
private String plateColorCode;
private String carTypeCode;
private String carColorCode;
private String laneNoCode;
private float catchSpeed;
private float limitSpeed;
private String illegalTypeId;
private String catchTime;
private String status;
private int version;
private String priority;
private String roadName;

private List<B> evidenceList = new ArrayList<B>();

B.java
private String name;
private String type;
private int seq;
private String resourceId;
private int width;
private int height;

       //这是另外一个表的字段
private String local;
private String remote;
private String absolute;
private String remark;


我的配置文件以及SQL如下:
<typeAlias alias="bvo" type="org.hitSys.audit.dao.vo.B"/>
<typeAlias alias="avo" type="org.hitSys.audit.dao.vo.A"/>
    
<resultMap id="BResult" class="bvo">
        <result property="name" column="name"/>
        <result property="type" column="type"/>
        <result property="seq" column="seq"/>
        <result property="resourceId" column="resource_id"/>
        <result property="width" column="width" nullValue="0"/>
        <result property="height" column="height" nullValue="0"/>
        <result property="local" column="local" />
        <result property="remote" column="remote" />
        <result property="absolute" column="absolute" />
        <result property="remark" column="remark" />
    </resultMap>
    
<resultMap id="AResult" groupBy="id" class="avo">
       <result property="id" column="id" />
        <result property="deviceId" column="device_id"/>
        <result property="plate" column="plate"/>
        <result property="plateColorCode" column="platecolor_code"/>
        <result property="plateTypeCode" column="platetype_code"/>
        <result property="carTypeCode" column="cartype_code"/>
        <result property="carColorCode" column="carcolor_code"/>