Search code examples
javasqlibatis

pass multiple value to <isNotEmpty> property


I'm new to iBatis. I would like if it's possible to pass multiple values into xml.

for example,

    <select id="getSth" resultClass="Object" parameterClass="Object">
    select * from table
<isNotEmpty property="startDate, endDate" prepend="AND">
    date_start >= #startDate# AND date_end <= #endDate#
</isNotEmpty>
</select>

is it possible like that? if not, any method??

Thanks in advance.


Solution

  • No, It is not possible to use multiple values in property attribute. But you can use nested tag to achieve this.

    <select id="getSth" resultClass="Object" parameterClass="Object">
         select * from table
         <isNotEmpty property="startDate" >
             <isNotEmpty property="endDate" >
                where date_start &gt;= #startDate# AND date_end &lt;= #endDate#
             </isNotEmpty>
        </isNotEmpty>
    </select>
    

    PS: you cannot use less than '<' , greater than '>' symbol inside the query. Instead use &lt; and &gt; respectively.