1、首先需要將resultMap進行改造,為了避免對其他sql的影響建議另外定義一個resultMapExtral,避免id相同,
2、然后在resultMapExtral中添加其它表的字段,若多個表中的字段名相同,要對查詢結果和resultMapExtral中相同的字段另起別名,
3、最后另外定義一個實體bean接收結果。相當於重新定義一個包含所有返回字段的entity,而不能用原先單表的entity。(RccpWorkerCenterCapacityEntityExtral)
4、也可以直接返回JsonObject對象,不用返回entity,這樣就不需要用resultMap了,更簡單一些。
定義結果集:
<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>