Search code examples
javasqldatabaseibatis

Check if bean is null in iBatis using dynamic mapped statements


i want to check if the bean that i use as parameter is null using dynamic statements.

<select id="my-query" resultClass="my.package.Results" parameterClass="my.package.Bean">
     //MY QUERY
</select>

There is a way to check if my bean is null directly inside the query or i must check if the property is available, null, etc?

Thanks


Solution

  • Yes, you can do that like bellow:

    <select ...>
    SELECT * FROM RESULT 
    <dynamic prepend="WHERE ">
       <isNull property="id">
          id IS NULL
       </isNull>
       <isNotNull property="id">
         id = #id#
       </isNotNull>
    </dynamic>
    </select>
    

    cheers and happy coding!