前言:

需求是查询级别为0的用户,User对象里的level字段的值为0,查询时居然没有查到为level为0的用户。

<select id="selectSelective" parameterType="com.agri.entity.User" resultMap="map">
  select * from sys_user where del_flag = 1
  <if test="level != null and level != ''">and level = #{level,jdbcType=INTEGER}</if>
</select>

查资料得知:mybatis规定,mybatis在进行判断时,会将integer=0的参数默认为‘’(空串)。

解决办法:

方法一:

去掉<if test="level != null and level != ''">中的and level != ” 即:
<if test="level != null">

方法二:

<if test="level != null and level != ''">中加入or level==0,即:
<if test="level != null and level != '' or level==0">

 

相关文章:

  • 2021-06-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-07
猜你喜欢
  • 2021-07-28
  • 2021-06-03
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案