当前位置: 代码迷 >> J2EE >> ibatis多表查询有关问题
  详细解决方案

ibatis多表查询有关问题

热度:235   发布时间:2016-04-19 22:17:28.0
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"/>
        <result property="laneNoCode" column="laneno_code"/>
        <result property="catchSpeed" column="catchspeed"/>
        <result property="limitSpeed" column="limitspeed"/>
        <result property="illegalTypeId" column="illegaltype_id"/>
        <result property="catchTime" column="catchTime"/>
        <result property="status" column="status"/>
        <result property="version" column="version"/>
        <result property="priority" column="priority"/>
        <result property="roadName" column="road_name"/>
        <result property="aList" resultMap="IllegalTemp.BResult" />
    </resultMap>

select t.id,
       t.device_id,
       t.plate,
       t.platetype_code,
       t.platecolor_code,
       t.catchspeed,
       t.laneno_code,
       t.limitspeed,
       t.illegaltype_id,
       t.status,
       t.version,
       to_char(t.catchtime, 'yyyy-MM-dd HH24:mi:ss') as catchtime,
       t.cartype_code,
       t.carcolor_code,
  相关解决方案