I have dynamic select query in mybatis, something like this:
<select id="genericSelect" parameterType="GenericQueryParameter" resultType="hashmap">
SELECT <if test="selectMode != null">${selectMode}</if> ${selectPart}
FROM ${fromPart}
<where>
<if test="fixedWherePart != null">${fixedWherePart}</if>
<if test="wherePart != null">AND ${wherePart}</if>
<if test="initialCondition != null and wherePart == null">AND ${initialCondition}</if>
</where>
<if test="groupByPart != null"> GROUP BY ${groupByPart}</if>
<if test="havingPart != null"> HAVING ${havingPart}</if>
<if test="order != null"> ORDER BY ${order}</if>
</select>
It is important for me to hashmap keys in result, be populated with column number, not column names. Is it somehow possible to make some custom handlers or anything else to do this?
Mybatis version is 3.1.1, an I’m using mapper interfaces to work with queries.
This is not possible on the way I wanted, so I changed query little bit. First of all I changed
selectPartto be array. Now I changed select part of query to be like this:Now I’m just using alias and
indexvar to put the the elements in hashmap, and keep information of order in select part of query.