Foreground to background Java when data date type conversion, Java to database data date format conversion
Foreground to Java:
Entity class with @datetimeformat so that is the passing of the empty string can also be transferred to the same format as the previous pass
@XmlElement (name = "Begindate")
@DateTimeFormat (pattern = "YYYYMMDD")
Private Date begindate;
End Date
@XmlElement (name = "EndDate")
@DateTimeFormat (pattern = "YYYYMMDD")
Private Date EndDate;
You don't need a format that's passed in front of you.
SimpleDateFormat sfdate = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
String Str=sfdate.format (Entity.gettrandate ());//entity.gettrandate ();
Java to database:
Java to database with To_date (' 2017-04-07 00:00:00 ', ' yyyy-mm-dd HH24:MI:SS ');
String str= "2017-04-07 00:00:00";
list<tbsettinmoney> tb= jdbctemplate.query ("select * from Tb_sett_inmoney t where T.acct_date=to_date (?, ' YYYY-MM -dd HH24:MI:SS ') ", New Object[]{str},new RowMapper () {
@Override
Public Object Maprow (ResultSet rs, int rownum) throws SQLException {
TODO auto-generated Method Stub
Tbsettinmoney tb= new Tbsettinmoney ();
Tb.setsupacctid (rs.getstring ("sup_acct_id"));
Tb.setcustflag (Rs.getint ("Cust_flag"));
Tb.settrandate (Rs.getdate ("tran_date"));
return TB;
}
});
Jdbctemplate.queryforlist ("select * from Tb_sett_fund t where t.sup_acct_id=?", New Object[]{str}, New Tbsettfund ());
System.out.println (Tb.size ());