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

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

定义结果集:

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" />
    

sql查询语句:

你可能感兴趣的:(u,笔记)