MyBatis version
3.4.4
Database vendor and version
mysql
Test case or example project
<select id="select" parameterType="string" resultType="map">
select * from table_name
<trim prefix="WHERE" prefixOverrides="AND |OR ">
<if test="id !='' and id !=null">
and `id` = #{id}
</if>
<if test="username !='' and username !=null">
and `username` = #{username}
</if>
</trim>
</select>
Steps to reproduce
I set prefixOverrides value is "AND |OR " (AND followed by 2 blank space)。it will not remove remove prefix "and"
Expected result
set prefixOverrides value " AND | OR",prefix "and" or "or" will be remove
Actual result
Comment From: mnisummer
source code is
i think if condition change to " trimmedUppercaseSql.startsWith(toRemove) || trimmedUppercaseSql.startsWith(toRemove.trim()) " will fix this bug
Comment From: harawata
Hello @mnisummer ,
I'm sorry, but that is a misconfiguration. It's clearly documented.
The prefixOverrides attribute takes a pipe delimited list of text to override, where whitespace is relevant.
The proposed change will create a new more serious bug.
<trim prefix="WHERE" prefixOverrides="AND |OR ">
organization = #{organization}
</trim>
will become
where ganization = #{organization}
For WHERE clause, you should use <where />
tag.