1iqueen

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

[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>
posted on 2015-01-22 20:55  1iqueen  阅读(16476)  评论(0编辑  收藏  举报