MyBatis anomaly Invalid comparison:java.util.Date and java.lang.String

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.