MyBatis jdbcType=DATE 和 jdbcType=TIMESTAMP 的区别

起因经过结果

今天写代码,写一个用时间筛选的功能。

有一个近三月的按钮,前台传三个月以前的日期和今天的日期。后台使用String接收,接收到的格式为:

2018-09-04

使用

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

转换成Date,但是今天(假设今天是2018-09-04)十二点的数据就已经筛选不到了,所以对时间又进行了修改:

            endDate=sdf.parse(end);
            endDate.setTime(endDate.getTime() 
            + (1000l*60l*60l*24l)-1000l);
            // 开始时间不需要修改。

然后执行查询,部分查询语句下:

<if test="begin!=null ">
    and t.create_time &gt;=#{begin,jdbcType=DATE}
</if>
<if test="end!=null ">
    and t.create_time &lt;= #{end,jdbcType=DATE}
</if>

但是发现仍然查不出来今天十二点的数据。后来注意到,以前用的都是:

#{end,jdbcType=TIMESTAMP}

然后把sql改成:

<!-- 就是把DATA改成TIMESTAMP了  -->
<if test="begin!=null ">
    and t.create_time &gt;=#{begin,jdbcType=TIMESTAMP}
</if>
<if test="end!=null ">
    and t.create_time &lt;= #{end,jdbcType=TIMESTAMP}
</if>

执行查询,正常了。

结论

根据自己经历和查询,发现:
无论是传参:

and t.create_time &gt;=#{end,jdbcType=TIMESTAMP}

还是设置返回值:

<result column="create_time" property="createTime" 
    jdbcType="TIMESTAMP"/>

jdbcType=”DATE” 都忽略了 时分秒, 无论是否有时分秒,都设置为了 00:00:00;
而jdbcType=”TIMESTAMP” 则 年月日时分秒全部设置,没有忽略。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
<mapper namespace="com.cskaoyan.mapper.MarketOrderMapper"> <resultMap id="BaseResultMap" type="com.cskaoyan.bean.MarketOrder"> <id column="id" jdbcType="INTEGER" property="id" /> <result column="user_id" jdbcType="INTEGER" property="userId" /> <result column="order_sn" jdbcType="VARCHAR" property="orderSn" /> <result column="order_status" jdbcType="SMALLINT" property="orderStatus" /> <result column="aftersale_status" jdbcType="SMALLINT" property="aftersaleStatus" /> <result column="consignee" jdbcType="VARCHAR" property="consignee" /> <result column="mobile" jdbcType="VARCHAR" property="mobile" /> <result column="address" jdbcType="VARCHAR" property="address" /> <result column="message" jdbcType="VARCHAR" property="message" /> <result column="goods_price" jdbcType="DECIMAL" property="goodsPrice" /> <result column="freight_price" jdbcType="DECIMAL" property="freightPrice" /> <result column="coupon_price" jdbcType="DECIMAL" property="couponPrice" /> <result column="integral_price" jdbcType="DECIMAL" property="integralPrice" /> <result column="groupon_price" jdbcType="DECIMAL" property="grouponPrice" /> <result column="order_price" jdbcType="DECIMAL" property="orderPrice" /> <result column="actual_price" jdbcType="DECIMAL" property="actualPrice" /> <result column="pay_id" jdbcType="VARCHAR" property="payId" /> <result column="pay_time" jdbcType="TIMESTAMP" property="payTime" /> <result column="ship_sn" jdbcType="VARCHAR" property="shipSn" /> <result column="ship_channel" jdbcType="VARCHAR" property="shipChannel" /> <result column="ship_time" jdbcType="TIMESTAMP" property="shipTime" /> <result column="refund_amount" jdbcType="DECIMAL" property="refundAmount" /> <result column="refund_type" jdbcType="VARCHAR" property="refundType" /> <result column="refund_content" jdbcType="VARCHAR" property="refundContent" /> <result column="refund_time" jdbcType="TIMESTAMP" property="refundTime" /> <result column="confirm_time" jdbcType="TIMESTAMP" property="confirmTime" /> <result column="comments" jdbcType="SMALLINT" property="comments" /> <result column="end_time" jdbcType="TIMESTAMP" property="endTime" /> <result column="add_time" jdbcType="TIMESTAMP" property="addTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="deleted" jdbcType="BIT" property="deleted" /> </resultMap>
05-30

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值