首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

ibatIS的sqlMap怎么插入sysdate

2012-07-26 
ibatIS的sqlMap如何插入sysdate使用ibatIS插入系统时间,代码一般是 new Date()直接写入系统时间,但是我们

ibatIS的sqlMap如何插入sysdate

使用ibatIS插入系统时间,代码一般是 new Date()直接写入系统时间,但是我们用的Oracle数据库,new Date()

默认只能插入年-月-日,没有时分秒,ibatIS不能自动处理。

?

一、insert直接命名为sysdate:

<insert id="insert" parametername="code"><update id="update" parameter" property="bussinessId">BUSSINESS_ID = #bussinessId# </isNotNull><isNotNull prepend="," property="bussinessNote">BUSSINESS_NOTE = #bussinessNote# </isNotNull><isNotEmpty prepend="," property="bussinessNoteDate">BUSSINESS_NOTE_DATE = sysdate</isNotEmpty><isNotNull prepend="," property="bussinessNoteState">BUSSINESS_NOTE_STATE = #bussinessNoteState# </isNotNull><isNotNull prepend="," property="state">STATE = #state# </isNotNull>WHEREBUSSINESS_ID=#bussinessId# </update>

?

2.代码中再使用时,可以new Date(),sqlMap就会自动插入当前数据库系统时间,时分秒格式!

/*1.发送短信前先向数据库发出记录,记录要发送的短信信息*/String ranNum = KeyedDigestMD5.getKeyedDigest(VerificationGen.getVerification(4), "")                                                     .toUpperCase();TBussinessSafe tbs = service.queryUserById(bussinessId.trim());tbs.setBussinessNote(ranNum);//要发送的短信信息tbs.setBussinessNoteDate(new Date());//商户短信密码到期时间tbs.setBussinessNoteState("17");//短信是否验证,默认17未读取service.updateBussinessSafe(tbs);

?

?

三、不插入系统时间但是还要显示 年-月-日 时:分:秒

1.sqlMap文件

<update id="update" parameter" property="bussinessId">BUSSINESS_ID = #bussinessId# </isNotNull><isNotEmpty prepend="," property="bussinessNoteDate">BUSSINESS_NOTE_DATE = sysdate</isNotEmpty><isNotNull prepend="," property="bussinessLastDate">BUSSINESS_LAST_DATE = #bussinessLastDate:TIMESTAMP# </isNotNull><isNotNull prepend="," property="bussinessPassReset">BUSSINESS_PASS_RESET = #bussinessPassReset:DATE# </isNotNull><isNotNull prepend="," property="bussinessComm">BUSSINESS_COMM = #bussinessComm:NUMERIC# </isNotNull><isNotNull prepend="," property="bussinessCommDefault">BUSSINESS_COMM_DEFAULT = #bussinessCommDefault:NUMERIC# </isNotNull>WHEREBUSSINESS_ID=#bussinessId# </update>

?###把BUSSINESS_LAST_DATE = #bussinessLastDate:DATE# 改为 TIMESTAMP

?

2.action中代码

/** * 1.更新登录安全信息:登录时间、登录IP */Date newDate = new Date();String newID = getRequest().getRemoteAddr();String oldID = "";if(tbs.getBussinessLoginIp() != null){oldID = tbs.getBussinessLoginIp();}Date oleDate = null;if(tbs.getBussinessLoginDate() != null){oleDate = tbs.getBussinessLoginDate();}tbs.setBussinessLastDate(oleDate);tbs.setBussinessLastIp(oldID);tbs.setBussinessLoginDate(newDate);tbs.setBussinessLoginIp(newID);if(flag.equals("true")){tbs.setBussinessNoteState("16");}//更新商户登入信息service.updateBussinessSafe(tbs);

热点排行