Skip to content

Latest commit

 

History

History
29 lines (28 loc) · 720 Bytes

mybatis_xml常用写法-使用like关键字.md

File metadata and controls

29 lines (28 loc) · 720 Bytes

需求: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>

参考文章