MATLAB 2018-05-19
在属性中定义了日期字段
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")//将返回的时间转换为日期格式<br />@DateTimeFormat(pattern = "yyyy-MM-dd")//将日期格式的转换为时间<br />private Date productionDate;//生产日期<br /><br />
public Date getProductionDate() {<br /> return productionDate;<br />}<br /><br />public void setProductionDate(Date productionDate) {<br /> this.productionDate = productionDate;<br />}<br /><br />
<select id="queryRecordByGoodsId" resultType="com.jxc.model.StockBrandGoodsDemo"><br /> SELECT demo.demo_id AS demoId,demo.brand_id AS brandId,demo.brand_name AS brandName,demo.goods_id AS goodsId,<br /> demo.goods_name AS goodsName,demo.pick_number AS pickNumber,demo.retail_price AS retailPrice<br /> FROM brand_goods_demo demo<br /> WHERE demo.store_id = #{storeId} AND demo.goods_id = #{goodsId}<br /><br /> <if test="productionDate != null and productionDate != ''">//代码运行到这里就报错了
<em> and DATE_FORMAT(demo.production_date,'%y-%M-%d') = DATE_FORMAT(#{productionDate,jdbcType=TIMESTAMP},'%y-%M-%d')<br /> </if><br /></select><br /><br /><br />原工程中配置的是mybatis-3.2.8, 而我测试工程中用的是mybatis-3.3.0.后来在网上找了一下才知道, 原来这是mybatis 3.3.0中对于时间参数进行比较时的一个bug. 如果拿传入的时间类型参数与空字符串''进行对比判断则会引发异常. 所以在上面的代码中去该该判断, 只保留非空判断就正常了<br /><br />就是把字段判空字符串删除就行了<br /></em>
<if test="productionDate != null">//就像这样
<em> and DATE_FORMAT(demo.production_date,'%y-%M-%d') = DATE_FORMAT(#{productionDate,jdbcType=TIMESTAMP},'%y-%M-%d')<br /> </if></em>
<em> </em>