ibatis动态sql使用两个条件

ant*_*ell 0 ibatis mybatis

我想使用动态sql语句,仅当变量不为null且大于零时才执行.像这样:

<isNotNull prepend="AND" property="ProprietaryId">
    <isGreaterThan prepend="AND" property="ProprietaryId" compareValue="0">
        G.PROPRIETARY_ID = #ProprietaryId#
    </isGreaterThan>
</isNotNull>
Run Code Online (Sandbox Code Playgroud)

但没有预先加两个'AND'.

我已经阅读了文档,但没有找到好的例子.

And*_*oni 6

要解决这个问题,我几乎从不使用"prepend"功能,而是写一个这样的sql:

WHERE 1=1
<isNotNull property="ProprietaryId">
    <isGreaterThan property="ProprietaryId" compareValue="0">
    AND G.PROPRIETARY_ID = #ProprietaryId#
    </isGreaterThan>
</isNotNull>
Run Code Online (Sandbox Code Playgroud)