我有三个表,例如A,B,C;这是我的resultMap
WITH your_table AS (SELECT 1 ID, 1234512 nic, NULL ntn, NULL mbl, 'ABC' NAME FROM dual UNION ALL
SELECT 2 ID, NULL nic, 321 ntn, NULL mbl, 'ABC' NAME FROM dual UNION ALL
SELECT 3 ID, NULL nic, NULL ntn, 5421 mbl, 'ABC' NAME FROM dual UNION ALL
SELECT 4 ID, 541245 nic, 624 ntn, NULL mbl, 'ABC' NAME FROM dual)
SELECT ID,
COALESCE(nic, ntn, mbl) nic_ntn_mbl,
NAME
FROM your_table;
ID NIC_NTN_MBL NAME
---------- ----------- ----
1 1234512 ABC
2 321 ABC
3 5421 ABC
4 541245 ABC
这是我的SQL查询
<resultMap id="picUserResultMap" type="PicUserAlias">
<id property="id" column="ID"></id>
<result property="bindId" column="BINDID"></result>
<result property="createDate" column="CREATEDATE"></result>
<result property="pictureId" column="PICTUREID"></result>
<result property="picture" column="PICTURE"></result>
<result property="picDescribe" column="PICDESCRIBE"></result>
<result property="pictureNo" column="PICTURENO"></result>
<result property="userId" column="USERID"></result>
<collection property="picTypeUserList" ofType="picTypeUserAlias">
<result property="userId" column="userid"></result>
<result property="picTypeId" column="pictypeid"></result>
<result property="content" column="content"></result>
<result property="isTags" column="istags"></result>
</collection>
<collection property="picDiscussList" ofType="PicDiscussAlias">
<result property="id" column="id"></result>
<result property="discussUser" column="discussuser"></result>
<result property="userId" column="userid"></result>
<result property="picUserId" column="picuserid"></result>
<result property="content" column="content"></result>
</collection>
当我查询出来时,数据不正确,picDiscussList就像picTypeUserList 我不知道为什么 任何帮助,将不胜感激。
答案 0 :(得分:0)
Read the documentation about Advanced Result Maps。
这两个集合都需要一个id,例如:用<result property="picTypeId" column="pictypeid"></result>
替换<id property="picTypeId" column="pictypeid"/>
类型picTypeUserAlias
和PicDiscussAlias
不需要userid和id属性。