[Java]如何把当前时间插入到数据库
1.在orderDao.java中
/** 设置订单*/
public void setOrder(Order order){
Date time = new Date(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String current = sdf.format(time);
order.setReceivedata(current);
this.sqlSessionTemplate.update("setOrder",order);
}
2.在orderMapper.xml中
<insert id="insertOrder" parameterType="Order">
insert into ORDERS (
ID,
OUTSETSTATIONID,
DESTSTATIONID,
ORDERSTATUS,
VEHICLEID,
RECEIVEDATA,
GOODSNAME,
GOODSNUMBER,
GOODSTYPEID,
GOODSTOTALWEIGHT,
GOODSTOTALVOLUME,
TOTALFARE,
SENDERNAME,
SENDERMOBILEPHONE,
SENDERADDRESS,
SENDERZIPCODE,
ADDRESSEENAME,
ADDRESSEEMOBILEPHONE,
ADDRESSEEADDRESS,
ADDRESSEEZIPCODE,
REMARK,
WAY_ID
)values(
#{id},
#{outsetstationid},
#{deststationid},
'已发货',
#{vehicleid},
to_date(#{receivedata},'yyyy-mm-dd hh24:mi:ss'),
#{goodsname},
#{goodsnumber},
#{goodstypeid},
#{goodstotalweight},
#{goodstotalvolume},
#{totalfare},
#{sendername},
#{sendermobilephone},
#{senderaddress},
#{senderzipcode},
#{addresseename},
#{addresseemobilephone},
#{addresseeaddress},
#{addresseezipcode},
#{remark},
#{way_id}
)
</insert>