mybatis的动态sql之if test用法

2020-04-09 14:49:03 浏览数 (1)

参数为String,if test读取该参数代码:

代码语言:javascript复制
<select id="getMaxDepartId" parameterType="java.lang.String" resultType="java.lang.String">
        SELECT MAX(DEPART_ID) FROM T_P_DEPART 
        <where>
            <if test="_parameter!=null and _parameter!=''">  
                AND DEPART_PID = #{departId,jdbcType=VARCHAR} 
            </if>
            <if test="_parameter==null or _parameter==''">  
                AND DEPART_PID IS NULL
            </if>
        </where>
    </select>

参数为pojo , if test读取该参数代码:

代码语言:javascript复制
<select id="findShopByName" parameterType="ShopVo" resultType="ShopCustomer">
    select * from shop 
    <where>
            <if test="shopCustomer.shopname!=null and  shopCustomer.shopname!=''">
                shop.shopname like '%${shopCustomer.shopname}%'
            </if>
            <if test="shopCustomer.shopname==null or shopCustomer.shopname==''">  
                AND shop.shopname is null
            </if>
    </where>
</select>

0 人点赞