天天看點

mybatis if 詳解

1.if test 比較

與字元串比較

<when test="item.attrDbKey == 'brand_name'.toString()">
        // 
     <when test="item.attrDbKey=='brand_name'">
           

與boolean比較

//hasRelated 為boolean型
 <if test="hasRelated">
           

2.if else寫法

choose -when -otherwise

<choose>
                <when test="item.id != null and item.id !=''">
                    #{item.id,jdbcType=CHAR},
                </when>
                <otherwise>
                    '',
                </otherwise>
            </choose>
           

補充:

ifnull(exp,v)

當exp為null,用v表示他的值。

sql中exp若表示表字段,值得是該字段對應的值