0

mybatis

select id="selectPlur" parameterType="map" resultMap="elementResultMap"
${sql}
/select

mysql

select * from (select * from ELEMENT where I_NO=1) T1
inner join (select * from ELEMENT where I_NO=3) T2 using (G_NO)
inner join ( select * from ELEMENT where I_NO=5) T3 using (G_NO)

mysql data result

G_NO | I_NO | I_REQ | I_NO | I_REQ | I_NO | I_REQ |
    1     |    1    |    10     |    3     |    20     |    5   |    1      |
    4     |    1    |    100   |    3     |    10     |    5   |    1      |

ajax result

[0]"gNo": 1
    "iNo": 1
    "iReq": 10
[1]"gNo": 4
    "iNo": 1
    "iReq": 100

ajax result what I want

[0]"gNo": 1
    "iNo": 1
    "iReq": 10
    "iNo": 3
    "iReq": 20
    "iNo": 5
    "iReq": 1
[1]"gNo": 4
    "iNo": 1
    "iReq": 100
    "iNo": 3
    "iReq": 10
    "iNo": 5
    "iReq": 1

in mySQL, I execute ‘mysql’ statement and it returns what I want like ‘mysql data result’.
but I`m using mybatis with eclipse
because of property name, result has only one “iNo” and “iReq” like ‘ajax result’
How can I get result like ‘ajax result what I want”?

1 Answers1

0

You can't do this directly because most JSON implementations do not support duplicate keys.

You might need to change the structure of the data you return to client for example rename the columns like this:

select G_NO, T1.I_NO AS T1_I_NO, T1.I_REQ AS T1_I_REQ,
       T2.I_NO AS T2_I_NO, T2.I_REQ AS T2_I_REQ,
       T3.I_NO AS T3_I_NO, T3.I_REQ AS T3_I_REQ
  from (select * from ELEMENT where I_NO=1) T1 
  inner join (select * from ELEMENT where I_NO=3) T2 using (G_NO) 
  inner join ( select * from ELEMENT where I_NO=5) T3 using (G_NO)  

In this case the result would be

[0]"gNo": 1 
   "t1INo": 1 
   "t1IReq": 10 
   "t2INo": 3
   "t2IReq": 20 
   "t3INo": 5 
   "t3IReq": 1 
[1]"gNo": 4 
   "t1INo": 1 
   "t1IReq": 100 
   "t2INo": 3
   "t2IReq": 10 
   "t3INo": 5 
   "t3IReq": 1 
Community
  • 1
  • 1