Home > Back-end >  Ask, mybatis how to encapsulate the results of a query into an array
Ask, mybatis how to encapsulate the results of a query into an array

Time:01-31

Such as a SQL is I say time and values, and if I return to map XML to specify the return value, because I am a query all of the data, all the dao will use List To accept, the last is similar to
 

Value: {time: '2020-01-15', '5'},
Value: {time: '2020-01-16', '4'},
Value: {time: '2020-01-17', '2'}
]

But now I hope the return value is
 

[' 2020-01-15 ', '5'],
[' 2020-01-16 ', '4'],
[' 2020-01-17 ', '1')

]

CodePudding user response:

First said the default implementation, resultMap estimates that this thing is difficult to achieve, because it cannot know you inside that array, each position which a field of the concrete corresponding to the database!
As for the realization of the function of this, you want to solve is also very simple, one kind is mybatis plug-in mechanism, the second is the aop intercepted mapper interfaces, as long as do the results data transformation can!
But it is strongly recommended that you manually to conversion, if it is to play, then you randomly, if you company project, please don't fault