mybatis中如何将多个表的查询结果,放入结果集中返回

首先需要将resultMap进行改造,为了避免对其他sql的影响建议另外定义一个resultMapExtral,避免id相同,然后在resultMapExtral中添加其它表的字段,若多个表中的字段名相同,要对查询结果和resultMapExtral中相同的字段另起别名,最后另外定义一个实体bean接收结果。

定义结果集:

<resultMap id="BaseResultMapExtral"
        type="com.cybertron.service.rccp.entity.RccpWorkerCenterCapacityEntityExtral">
        <id column="workcenter_capacity_id" jdbcType="INTEGER"
            property="workercenterCapacityId" />        
        <result column="process_number" jdbcType="INTEGER" property="processNumber" />
        <result column="product_name" jdbcType="VARCHAR" property="productName" />
        <result column="product_id" jdbcType="INTEGER" property="productId" />
        <result column="average_volume" jdbcType="INTEGER" property="averageVolume" />
        <result column="single_process_time" jdbcType="DOUBLE"
            property="singleProcessTime" />
        <result column="change_model_time" jdbcType="DOUBLE" property="changeModelTime" />
        <result column="product_prepare_time" jdbcType="DOUBLE"
            property="productPrepareTime" />
        <result column="take_down_time" jdbcType="DOUBLE" property="takeDownTime" />
        <result column="unit_transport_size" jdbcType="DOUBLE"
            property="unitTransportSize" />
        <result column="s_resource_id" jdbcType="NUMERIC" property="sResourceId" />
        <result column="ad_wf_node_id" jdbcType="NUMERIC" property="adWfNodeId" />
        <result column="name" jdbcType="VARCHAR" property="workcenterName" />
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
        <result column="create_user" jdbcType="VARCHAR" property="createUser" />
        <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
        <result column="modify_user" jdbcType="VARCHAR" property="modifyUser" />
        <result column="isdelete" jdbcType="BOOLEAN" property="isdelete" />
        <result column="isdefault" jdbcType="BOOLEAN" property="checkDefault" />
        <result column="is_key_wc" jdbcType="BOOLEAN" property="isKeyWc" />
        <result column="parent_product_id" jdbcType="NUMERIC" property="paproductId" />
          <result column="parentProductName" jdbcType="VARCHAR" property="parentProductName" />
        <result column="adWfNodeName" jdbcType="VARCHAR" property="adWfNodeName" />
    </resultMap>

sql查询语句:

<select id="queryAll" resultMap="BaseResultMapExtral">
    select 
     rwc.* ,mp.name parentProductName,awn.name adWfNodeName
    from rccp_workcenter_capacity rwc,m_product mp,ad_wf_node awn
    where mp.m_product_id=rwc.parent_product_id and  awn.ad_wf_node_id=rwc.ad_wf_node_id
    </select>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值