js中定义变量为null,mybatis用对象接收该变量后无法判断其为null

本文介绍了一种在MyBatis中处理参数为null情况的方法,通过将参数设为空字符串而非null,解决了在SQL条件判断中无法正确识别null的问题。详细解释了在JavaScript中设置参数的方式以及如何避免在URL中出现null关键字。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

因为业务需求,需要将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 != ''">不起作用再深究

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值