Java Entity Date Type property value cannot be saved to the data table corresponding field
Project Framework:
Maven+springmvc+mybatis
Entity properties:
Recommended time
Private Java.util.Date recommenddate;
Database fields:
ALTER TABLE ' Resource '
ADD COLUMN ' recommend_date ' date NULL COMMENT ' recommended time ';
Property Assignment Value:
Resource.setrecommenddate (Dateutils.getnowdate ());
Related methods:
Get current time
/** * Get now time * * @return return Time type YYYY-MM-DD HH:mm:ss */public static Date getnowdate () {Date currenttime = new Date (); S Impledateformat formatter = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); String datestring = Formatter.format (currenttime); Parseposition pos = new Parseposition (8);D ate currenttime_2 = Formatter.parse (datestring, POS); return currenttime_2;}
Issue: Trace MySQL log when performing save discovery field value is null
Resourcemanager.saveorupdate (Resource);
Recommend_date = null
Cause Analysis:
The cause of this problem is estimated to be a type mismatch problem!
But there is no exception, there is no warning;
Workaround:
Later, due to the need to save the date time, the database type is changed to datetime;
Entity attribute mappings are:
Recommended time
Private Java.sql.Timestamp recommenddate;
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java Entity Date Type property value cannot be saved to the data table corresponding field