I am trying to dynamically include select query based on some input parameters. The following is what I am trying to achieve.
<sql id="query1">
  SELECT * from 
    table_1
   WHERE a = #{param1}
</sql>
<sql id="query2">
  SELECT * from 
    table_2
   WHERE b = #{param2}
</sql>
<select id = "selectSomethingFromDB">
  <include refid="#{readerIdName}" />
</select>
I am planning to pass the sql id name as parameter to the query and trying to dynamically choose the select query based on this param. (Sort of like a factory design implementation). However #{readerIdName} is not getting replaced with the value I am passing as param. Is something like this possible?
                        
The xml attributes at this level are not evaluated in runtime by mybatis.
You can use a single
<SQL id="...">query and an<if test="...">dynamic sql in it.