因为业务需求,需要将enterpriseId设为null,然后在mapper中进行判断:
<select id="searchFile" resultMap="BaseResultMap"
parameterType="com.xhu.entity.MyFile">
select
<include refid="Base_Column_List" />
from file where 1=1
<if test="name != null and name != ''">
and name like "%"#{name}"%"
</if>
<if test="enterpriseId != null and enterpriseId != ''">
and enterprise_id = #{enterpriseId}
</if>
limit #{page,jdbcType=INTEGER},#{rows,jdbcType=INTEGER}
</select>
我原来的做法是在js中定义其为null:var enterpriseId = null;
但是标签无法判断其为null。观察url发现这样传递url会变为
http://localhost:8080/ability_enhancement/searchFile?name=&enterpriseId=null&page=1&rows=20&sort=id&order=asc
然后灵机一动:var enterpriseId = ‘’;
问题解决,具体原因 <if test="enterpriseId != null and enterpriseId != ''">
不起作用再深究