Mybatis插入Oracle數(shù)據(jù)庫日期型數(shù)據(jù)過程解析
前端頁面type類型是:datetime-local,因?yàn)槿绻莇ate類型,只顯示年月日,不顯示時間,這個可以顯示時間
但插入時會以:2020-02-0202T10:10 這個格式出現(xiàn),所以下面代碼,將這個格式轉(zhuǎn)換為:2020-02-02 10:10 ,通過修改傳來的user,然后通過set方法修改。
/** * 新增用戶 * * @param user * @return */ @Override public boolean insertUser(User user) throws ParseException { //將日期格式化 try { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm"); Date date = formatter.parse(user.getBirth().trim() + ":.803+08:00"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); String sDate = sdf.format(date); user.setBirth(sDate); System.out.println(sDate); } catch (Exception e) { } return iRegisterMapper.insertUser(user) > 0; }
修改完畢后調(diào)用mapper文件的插入方法
<insert id="insertUser" parameterType="User"> insert into tb_user(id,uname,pwd,sex,birth,nickname,email,regtime) values(Sequence_User_Id.NEXTVAL,#{uname},#{pwd},#{sex},to_date('${birth}','yyyy-mm-dd hh:mi:ss'),#{nickname},#{email},to_date('${birth}','yyyy-mm-dd hh:mi:ss')) </insert>
這樣就可以插入正確的格式了
備注:
修改的方法:
<!--修改--> <update id="updateUser" parameterType="Map"> update tb_user <trim prefix="set" suffixOverrides=","> <if test="uname!=null">uname=#{uname},</if> <if test="pwd!=null">pwd=#{pwd},</if> <if test="name!=null">name=#{name},</if> <if test="sex!=null">sex=#{sex},</if> <if test="birth!=null">birth=to_date('${birth}','yyyy-mm-dd hh:mi:ss'),</if> <if test="addr!=null">addr=#{addr},</if> <if test="nickname!=null">nickname=#{nickname},</if> <if test="introduce!=null">introduce=#{introduce},</if> <if test="tel!=null">tel=#{tel},</if> <if test="email!=null">email=#{email},</if> </trim> where uname = #{oldUname} </update>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 詳解mybatis批量插入10萬條數(shù)據(jù)的優(yōu)化過程
- mybatis-plus 處理大數(shù)據(jù)插入太慢的解決
- mybatis的insert語句插入數(shù)據(jù)時的返回值的實(shí)現(xiàn)
- 如何在mybatis中向BLOB字段批量插入數(shù)據(jù)
- MybatisPlus中插入數(shù)據(jù)后獲取該對象主鍵值的實(shí)現(xiàn)
- Mybatis數(shù)據(jù)批量插入如何實(shí)現(xiàn)
- mybatis 批量將list數(shù)據(jù)插入到數(shù)據(jù)庫的實(shí)現(xiàn)
- Mybatis實(shí)現(xiàn)插入數(shù)據(jù)后返回主鍵過程解析
- Mybatis批量插入數(shù)據(jù)返回主鍵的實(shí)現(xiàn)
- Mybatis三種批量插入數(shù)據(jù)的方式
相關(guān)文章
Springboot微服務(wù)分布式框架Rouyi Cloud權(quán)限認(rèn)證(登錄流程之token解析)
這篇文章主要介紹了Springboot微服務(wù)分布式框架Rouyi Cloud權(quán)限認(rèn)證的相關(guān)知識,重點(diǎn)講解下整個框架的入口,登錄流程之token解析,感興趣的朋友跟隨小編一起看看吧2024-04-04HttpClient POST請求第三方接口問題(多參數(shù)傳參)
這篇文章主要介紹了HttpClient POST請求第三方接口問題(多參數(shù)傳參),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-07-07