原sql
<select id="getList" resultMap="ResultMapWithBLOBs" parameterType="com.macro.mall.model.PmsProductCategory">
select id, parent_id, name, level, product_count, product_unit, nav_status, show_status,
sort, icon, keywords, description
from pms_product_category
<where>
<if test="name != null and name != ''">and name like concat('%', #{name}, '%')</if>
<if test="navStatus != null and navStatus != ''">and nav_status = #{navStatus}</if>
<if test="showStatus != null and showStatus != ''">and show_status = #{showStatus}</if>
</where>
</select>
解决办法
去掉空字符串判断
<select id="getList" resultMap="ResultMapWithBLOBs" parameterType="com.macro.mall.model.PmsProductCategory">
select id, parent_id, name, level, product_count, product_unit, nav_status, show_status,
sort, icon, keywords, description
from pms_product_category
<where>
<if test="name != null and name != ''">and name like concat('%', #{name}, '%')</if>
<if test="navStatus != null">and nav_status = #{navStatus}</if>
<if test="showStatus != null">and show_status = #{showStatus}</if>
</where>
</select>
总结
mybatis中如果参数为’Integer
类型且为0
时,会被识别成""(空字符串)
处理, 所以应去掉空字符串判断