mybatis xml常用写法-使用like关键字

需求:xml中需要在where中拼接like语句

方法1:concat

<where>
    <trim  suffixOverrides="," >
        <if test="id != null and id != ''" >
            and id =  #{id}
        </if>
        <if test="name != null and name != ''" >
            and name like concat('%',#{name},'%')
        </if>
    </trim>
</where>

方法2:${}

<if test="examTypeName!=null and examTypeName!=''">
    and exam_type_name like '%${examTypeName}%'
</if>

方法3:#{}

<if test="examTypeName!=null and examTypeName!=''">
    and exam_type_name like "%"#{examTypeName}"%"
</if>

参考文章


版权声明:本文为evasnowind原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。