日期:2014-05-18  浏览次数:20721 次

Ibatis语句如何使用if判断
Ibatis语句如何使用if判断,哪位大虾有例子!

------解决方案--------------------
isNotNull
isEmpty
isGreaterEqual
isNotNull
isLessEqual
……

------解决方案--------------------
学习了。
------解决方案--------------------
XML code

<select id="getPersonsByName" resultClass="com.unmi.Person">       
      select id as id,name as name,passwd as passwd from person       
        <dynamic prepend="WHERE">       
            <isNotNull prepend="AND" property="name">       
                  (name like #name#)       
            </isNotNull>       
        </dynamic>       
</select>

------解决方案--------------------
XML code


<!-- find user list page -->
    <select id="find-count-of-users" parameterClass="User" resultClass="int">
        select count(*) from t_user
            <dynamic prepend="where">
                <isNotEqual property="type" compareValue="-1" prepend="AND">
                    user_type = #type#
                </isNotEqual>
                <isNotEmpty property="userName" prepend="and">
                    user_name like '%$userName$%'
                </isNotEmpty>
                <isNotEqual property="state" compareValue="3" prepend="AND">
                    user_state = #state#
                </isNotEqual>
                <isNotEqual property="usedSpaceSize" compareValue="-1" prepend="AND">
                    user_used_space_size >= #usedSpaceSize#
                </isNotEqual>
            </dynamic>
    </select>