Conversion of data date type from foreground to background Java, conversion of java to database data date format

 

Conversion of data date type from foreground to background Java, conversion of java to database data date format

 

Front desk to java:

Use @DateTimeFormat in the entity class so that the string passed in is empty can also be converted, it must be consistent with the format passed in earlier

 

@XmlElement(name = "BeginDate")

@DateTimeFormat(pattern = "yyyyMMdd")

private Date beginDate;

// end date

@XmlElement(name = "EndDate")

@DateTimeFormat(pattern = "yyyyMMdd")

private Date endDate;

 

 You don't need to care about the format passed earlier

SimpleDateFormat SFDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String str=SFDate.format(entity.getTranDate());//entity.getTranDate();

 

 

java to database:

Convert 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());

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326242550&siteId=291194637