是否有办法根据结果集中某列的值在Mybatis中创建List of Map。
下面解释我的方案是结果集。
这是Oracle分层查询的结果集:
SELECT * FROM (
SELECT *
FROM MA0101.MESSAGE_NOTIFICATION
START WITH ORIGINAL_MESSAGE_SEQ_NO IS NULL
CONNECT BY PRIOR MESSAGE_SEQUENCE_NO = ORIGINAL_MESSAGE_SEQ_NO
ORDER SIBLINGS BY LAST_UPDATED_DT DESC)
WHERE (SENDER_NYL_ID = 'T57HI9H' OR RECEIVER_NYL_ID = 'T57HI9H')
AND FISCAL_START_YR = '2013'
现在,对于ORIGINAL_MESSAGE_SEQ_NO的每个Null(空白)值,我需要在Map中创建一个新密钥(密钥将是MESSAGE_SEQUENCE_NO),该值将是该消息序列号下所有子消息的列表。
例如: 其中一个映射键是MESSAGE_SEQUENCE_NO = 12,列表将是序列为12,13和15的消息
任何帮助或想法?
答案 0 :(得分:0)
mybatis不支持开箱即用,但可以通过实现自定义ResultHandler
来完成。
为此,应修改查询以包含每行的键。像这样使用CONNECT_BY_ROOT
运算符:
SELECT * FROM (
SELECT *, CONNECT_BY_ROOT MESSAGE_SEQUENCE_NO as ROOT_MESSAGE_SEQUENCE_NO
FROM MA0101.MESSAGE_NOTIFICATION
START WITH ORIGINAL_MESSAGE_SEQ_NO IS NULL
CONNECT BY PRIOR MESSAGE_SEQUENCE_NO = ORIGINAL_MESSAGE_SEQ_NO
ORDER SIBLINGS BY LAST_UPDATED_DT DESC)
WHERE (SENDER_NYL_ID = 'T57HI9H' OR RECEIVER_NYL_ID = 'T57HI9H')
AND FISCAL_START_YR = '2013'
然后应该实现自定义ResultHandler
。在mybatis wiki中查找example。