How do I check for an empty string in the dynamic SQL of MyBatis? I find the code below in the documentaiton, but I want to check for empty string, not null.
<select id="findActiveBlogWithTitleLike" parameterType="Blog" resultType="Blog">
SELECT * FROM BLOG WHERE state = ‘ACTIVE’
<if test="title != null">
AND title like #{title}
</if>
</select>
In MyBatis you can use != ''
to compare with empty string, so in your query it would be something like:
<select id="findActiveBlogWithTitleLike" parameterType="Blog" resultType="Blog">
SELECT * FROM BLOG WHERE state = ‘ACTIVE’
<if test="title != null and title != ''">
AND title like #{title}
</if>
</select>