含有3个可选传递的参数,前端未传入参数,则默认为空字符串’ '(前端使用的是Vue)
查询出来的数据只有7条
<select id="selectTotal" resultType="java.lang.Integer">
select count(*) from b_users
<where>
<if test="userName!=null">
user_name like concat('%', #{userName}, '%')
</if>
<if test="userNickname!=null">
and user_nickname like concat('%', #{userNickname}, '%')
</if>
<if test="userTelNumber!=null">
and user_tel_number like concat('%', #{userTelNumber}, '%')
</if>
</where>
</select>
改为
<select id="selectTotal" resultType="java.lang.Integer">
select count(*) from b_users
<where>
<if test="userName!=null and userName!=''">
user_name like concat('%', #{userName}, '%')
</if>
<if test="userNickname!=null and userNickname!=''">
and user_nickname like concat('%', #{userNickname}, '%')
</if>
<if test="userTelNumber!=null and userTelNumber!=''">
and user_tel_number like concat('%', #{userTelNumber}, '%')
</if>
</where>
</select>
<if>
便签有一个必填的属性test,test的属性值是一个符合OGNL要求的判断表达式,
表达式的结果可以是true或者false,初次之外所有的的非0值都为true,只有0为false。
且有如下规则:
1.判断条件property!=null
或者property==null
:适用于任何类型的字段,用于判断属性值是否为空
2.判断条件property!=''
或者property==''
:仅适用于String类型的字段,用于判断是否为空字符串
3.and和or:当有多个判断条件时,适用and或or进行连接,嵌套的判断可以适用小括号分组。