mybatis参数接收后变为null
来源:14-4 ProductSellDailyDao的开发与测试
qq_陌路_7
2018-06-29
老师,我在写柱状图数据接口的时候,dao层传入的时间参数mybatis接收后变为null,我后台打印两个时间参数都是能打印出来的:endTime:2018-06-28 beginTime:2018-06-22,而且mapper.xml中<if test="startTime != null and endTime != null">这个判断也是通过的 打印的sql中带有 这个条件 date_format(tpsd.create_time,'%Y-%m-%d') BETWEEN date_format(?,'%Y-%m-%d') AND date_format(?,'%Y-%m-%d') 但是接收的参数 为:Parameters: 3(Long), null, null 这是什么原因呢,搞了好久,希望老师能帮我解决一下。
写回答
2回答
-
同学可以试着把endTime和beginTime直接赋值,就是直接传个常量值进去看看效果如何,如果正常,再对比下之前传入的endTime和beginTime的差别
012018-07-04 -
翔仔
2018-06-29
同学好,请问你的tpsd.create_time tpsd是啥,你可以对应我的配置来看看,我的是没有问题的
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.imooc.o2o.dao.ProductSellDailyDao"> <resultMap id="productSellDailyResultMap" type="com.imooc.o2o.entity.ProductSellDaily"> <id column="product_sell_daily_id" property="productSellDailyId" /> <result column="create_time" property="createTime" /> <result column="total" property="total" /> <association property="product" column="product_id" javaType="com.imooc.o2o.entity.Product"> <id column="product_id" property="productId" /> <result column="product_name" property="productName" /> </association> <association property="shop" column="shop_id" javaType="com.imooc.o2o.entity.Shop"> <id column="shop_id" property="shopId" /> <result column="shop_name" property="shopName" /> </association> </resultMap> <select id="queryProductSellDailyList" resultMap="productSellDailyResultMap"> SELECT psd.product_sell_daily_id, psd.create_time, psd.total, s.shop_id, s.shop_name, p.product_id, p.product_name FROM tb_product_sell_daily psd, tb_shop s, tb_product p <where> psd.shop_id = s.shop_id and psd.product_id = p.product_id <!-- 按店铺查询 --> <if test="productSellDailyCondition.shop!=null and productSellDailyCondition.shop.shopId!=null"> and psd.shop_id = #{productSellDailyCondition.shop.shopId} </if> <!-- 按商品名模糊查询 --> <if test="productSellDailyCondition.product!=null and productSellDailyCondition.product.productName!=null"> and p.product_name like '%${productSellDailyCondition.product.productName}%' </if> <if test="beginTime!=null and endTime!=null"> and date_format(psd.create_time,'%Y-%m-%d') between date_format(#{beginTime},'%Y-%m-%d') and date_format(#{endTime},'%Y-%m-%d') </if> <if test="beginTime!=null and endTime==null"> and date_format(psd.create_time,'%Y-%m-%d') >= date_format(#{beginTime},'%Y-%m-%d') </if> <if test="beginTime==null and endTime!=null"> and date_format(psd.create_time,'%Y-%m-%d') <= date_format(#{endTime},'%Y-%m-%d') </if> </where> order by psd.product_id, psd.create_time </select> <insert id="insertProductSellDaily" parameterType="com.imooc.o2o.entity.ProductSellDaily"> INSERT INTO tb_product_sell_daily(product_id,shop_id,create_time,total) ( SELECT product_id,shop_id,date_format(create_time,'%Y-%m-%d'),count(product_id) AS total FROM tb_user_product_map WHERE date_format(create_time,'%Y-%m-%d') = date_sub(curdate(),interval 1 day) GROUP BY product_id) </insert> <insert id="insertDefaultProductSellDaily"> INSERT INTO tb_product_sell_daily(product_id,shop_id,create_time,total) ( SELECT p.product_id,p.shop_id,date_sub(curdate(),interval 1 day),0 AS total FROM tb_product p WHERE p.product_id not in (select product_id from tb_product_sell_daily where date_format(create_time,'%Y-%m-%d') = date_sub(curdate(),interval 1 day)) ) </insert> </mapper>
012018-06-29
相似问题