[Java]如何把當前時間插入到數據庫

[Java]如何把當前時間插入到數據庫java

1.在orderDao.java中sql

/** 設置訂單*/
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>
相關文章
相關標籤/搜索