Integer类型传值为0时,在Mapper.xml中被 <if test="status !=null and status !=''">条件过滤

0引发的Mybatis查询陷阱

0引起的风波

昨天写了一个查询功能,如下图,“请选择”value=“” ,“正常” value=“0” ,“禁用” value=“1” ,查询的时候“正常”的结果与“请选择“的查询结果一样,DEBUG看后台的值的确是0,但是被Mybatis中if条件的 status !=’’" 过滤掉了。。。。。。>_<

去掉这个条件就。好。了

 <if test="status !=null>
 and status =  #{status,jdbcType=INTEGER}
 </if>

在这里插入图片描述

<label class="layui-form-label">状态:</label>
<div class="layui-input-block">
     <select  id="search_garastatus" name="search_garastatus" lay-filter="search_garastatus">
              <option value=""></option>
 			  <option value="0">正常</option>
 		      <option value="1">禁用</option>
      </select>
</div>
解释一下列语句的语法,纯文本输出.<?xml version="1.0" encoding="UTF-8" ?> <!-- sky-server\src\main\resources\mapper\DishMapper.xml --> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="com.sky.mapper.DishMapper"> <insert id="insert" useGeneratedKeys="true" keyProperty="id"> insert into dish (name, category_id, price, image, description, create_time, update_time, create_user, update_user,status) values (#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser},#{status}) </insert> <select id="pageQuery" resultType="com.sky.vo.DishVO"> select d.*,c.name as categoryName from dish d left outer join category c on d.category_id = c.id <where> <if test="name != null"> and d.name like concat('%',#{name},'%') </if> <if test="categoryId != null"> and d.category_id = #{categoryId} </if> <if test="status != null"> and d.status = #{status} </if> </where> order by d.create_time desc </select> <select id="list" resultType="com.sky.entity.Dish"> select * from dish <where> <if test="categoryId != null"> and category_id = #{categoryId} </if> <if test="name != null"> and name = #{name} </if> <if test="status != null"> and status = #{status} </if> </where> order by create_time desc </select> <select id="countByMap" resultType="java.lang.Integer"> select count(id) from dish <where> <if test="status != null"> and status = #{status} </if> <if test="categoryId != null"> and category_id = #{categoryId} </if> </where> </select> <update id="update"> update dish <set> <if test="name != null"> name = #{name}, </if> <if test="categoryId != null"> category_id = #{categoryId}, </if> <if test="price != null"> price = #{price}, </if> <if test="image != null"> image = #{image}, </if> <if test="description != null"> description = #{description}, </if> <if test="status != null"> status = #{status}, </if> <if test="updateTime != null"> update_time = #{updateTime}, </if> <if test="updateUser != null"> update_user = #{updateUser}, </if> </set> where id = #{id} </update> </mapper>
10-25
解释一下列语句的语法,纯文本输出.<?xml version="1.0" encoding="UTF-8" ?> <!-- sky-server\src\main\resources\mapper\OrderMapper.xml --> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="com.sky.mapper.OrderMapper"> <insert id="insert" useGeneratedKeys="true" keyProperty="id"> insert into orders(number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, remark, phone, address, user_name, consignee, cancel_reason, rejection_reason, cancel_time, estimated_delivery_time, delivery_status, delivery_time, pack_amount, tableware_number, tableware_status) values (#{number}, #{status}, #{userId}, #{addressBookId}, #{orderTime}, #{checkoutTime}, #{payMethod}, #{payStatus}, #{amount}, #{remark}, #{phone}, #{address}, #{userName}, #{consignee}, #{cancelReason}, #{rejectionReason}, #{cancelTime}, #{estimatedDeliveryTime}, #{deliveryStatus}, #{deliveryTime}, #{packAmount}, #{tablewareNumber}, #{tablewareStatus}) </insert> <update id="update" parameterType="com.sky.entity.Orders"> update orders <set> <if test="cancelReason != null and cancelReason!='' "> cancel_reason=#{cancelReason}, </if> <if test="rejectionReason != null and rejectionReason!='' "> rejection_reason=#{rejectionReason}, </if> <if test="cancelTime != null"> cancel_time=#{cancelTime}, </if> <if test="payStatus != null"> pay_status=#{payStatus}, </if> <if test="payMethod != null"> pay_method=#{payMethod}, </if> <if test="checkoutTime != null"> checkout_time=#{checkoutTime}, </if> <if test="status != null"> status = #{status}, </if> <if test="deliveryTime != null"> delivery_time = #{deliveryTime} </if> </set> where id = #{id} </update> <select id="pageQuery" resultType="com.sky.entity.Orders"> select * from orders <where> <if test="number != null and number!=''"> and number like concat('%',#{number},'%') </if> <if test="phone != null and phone!=''"> and phone like concat('%',#{phone},'%') </if> <if test="userId != null"> and user_id = #{userId} </if> <if test="status != null"> and status = #{status} </if> <if test="beginTime != null"> and begin_time = #{beginTime} </if> <if test="endTime != null"> and end_time = #{endTime} </if> </where> order by order_time desc </select> <select id="sumByMap" resultType="java.lang.Double"> select sum(amount) from orders <where> <if test="begin != null"> and order_time > #{begin} </if> <if test="end != null"> and order_time < #{end} </if> <if test="status != null"> and status = #{status} </if> </where> </select> <select id="getOrderCount" resultType="java.lang.Integer"> select count(id) from orders <where> <if test="begin != null"> and order_time > #{begin} </if> <if test="end != null"> and order_time < #{end} </if> <if test="status != null"> and status = #{status} </if> </where> </select> <select id="getSalesTop10" resultType="com.sky.dto.GoodsSalesDTO"> select od.name,sum(od.number) number from order_detail od,orders o where od.order_id = o.id and o.status = 5 <if test="begin != null"> and o.order_time > #{begin} </if> <if test="end != null"> and o.order_time < #{end} </if> group by od.name order by number desc limit 0,10 </select> </mapper>
最新发布
10-25
<!-- 插入集合 --> <insert id="insertListSelective" parameterType="java.util.List"> INSERT INTO art_customer_leads_pool <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">id,</if> <if test="activityId != null">activity_id,</if> <if test="activityName != null">activity_name,</if> <if test="comCode != null">com_code,</if> <if test="comName != null">com_name,</if> <if test="customerName != null">customer_name,</if> <if test="licenseNo != null">license_no,</if> <if test="expiryMonth != null">expiry_month,</if> <if test="mobile != null">mobile,</if> <if test="referrerStaffNo != null">referrer_staff_no,</if> <if test="referrerType != null">referrer_type,</if> <if test="status != null">status,</if> <if test="source != null">source,</if> <if test="leadInboundTime != null">lead_inbound_time,</if> <if test="createTime != null">create_time,</if> <if test="updateTime != null">update_time,</if> </trim> VALUES <foreach collection="item" index="index" item="item" separator=","> <trim prefix="(" suffix=")" suffixOverrides=","> <if test="item.id != null">#{item.id, jdbcType=BIGINT},</if> <if test="item.activityId != null">#{item.activityId, jdbcType=VARCHAR},</if> <if test="item.activityName != null">#{item.activityName, jdbcType=VARCHAR},</if> <if test="item.comCode != null">#{item.comCode, jdbcType=VARCHAR},</if> <if test="item.comName != null">#{item.comName, jdbcType=VARCHAR},</if> <if test="item.customerName != null">#{item.customerName, jdbcType=VARCHAR},</if> <if test="item.licenseNo != null">#{item.licenseNo, jdbcType=VARCHAR},</if> <if test="item.expiryMonth != null">#{item.expiryMonth, jdbcType=DATE},</if> <if test="item.mobile != null">#{item.mobile, jdbcType=VARCHAR},</if> <if test="item.referrerStaffNo != null">#{item.referrerStaffNo, jdbcType=VARCHAR},</if> <if test="item.referrerType != null">#{item.referrerType, jdbcType=VARCHAR},</if> <if test="item.status != null">#{item.status, jdbcType=SMALLINT},</if> <if test="item.source != null">#{item.source, jdbcType=VARCHAR},</if> <if test="item.leadInboundTime != null">#{item.leadInboundTime, jdbcType=DATE},</if> <if test="item.createTime != null">#{item.createTime, jdbcType=DATE},</if> <if test="item.updateTime != null">#{item.updateTime, jdbcType=DATE},</if> </trim> </foreach> </insert> public interface ArtCustomerLeadsPoolExtMapper { int insertListSelective(@Param("item") List<ArtCustomerLeadsPool> record); }我这个那里写错了
03-12
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值