A date field is defined in a property
@JsonFormat (timezone = "gmt+8", pattern = "YYYY-MM-DD")//Convert the returned time to a date format
@DateTimeFormat (pattern = "YYYY-MM-DD")//Convert date format to time
Private date productiondate;//Production date
Public Date getproductiondate () {
return productiondate;
}
public void Setproductiondate (Date productiondate) {
This.productiondate = productiondate;
}
<select id= "Queryrecordbygoodsid" resulttype= "Com.jxc.model.StockBrandGoodsDemo" >
SELECT demo.demo_id as demoid,demo.brand_id as brandid,demo.brand_name as brandname,demo.goods_id as GoodsId,
Demo.goods_name as goodsname,demo.pick_number as picknumber,demo.retail_price as Retailprice
From Brand_goods_demo Demo
WHERE demo.store_id = #{storeid} and demo.goods_id = #{goodsid}
<if test= "Productiondate! = null and Productiondate! =" ">//code running here is an error.
and Date_format (demo.production_date, '%y-%m-%d ') = Date_format (#{productiondate,jdbctype=timestamp}, '%y-%M-%d ')
</if>
</select>
The original project was configured with mybatis-3.2.8, and I was using mybatis-3.3.0 in my Test project. Later on the internet to find a bit to know, originally this is MyBatis 3.3.0 in the time parameter comparison of a bug. An exception is thrown if you compare an incoming time type argument with an empty string '. So in the above code to go to the judgment, only leave the non-null judgment is normal
is to drop the field with an empty string.
<if test= "Productiondate! = null" >//just like this
and Date_format (demo.production_date, '%y-%m-%d ') = Date_format (#{productiondate,jdbctype=timestamp}, '%y-%M-%d ')
</if>
MyBatis anomaly Invalid comparison:java.util.Date and java.lang.String