Java通過mybatis插入Oracle資料庫中Date格式不顯示到時分秒問題
阿新 • • 發佈:2019-02-16
我在用mybatis generator生成程式碼後,執行查詢語句時,Oracle裡的Date型別欄位只精確到年月日,後面時分秒都為零。
後來發現是jdbcType問題,改成 jdbcType="TIMESTAMP" 就可以。(原先預設生成時是jdbcType="DATE")
ps:實體類裡Date是Java.util.Date包裡的,不是java.sql.Date,否則也會只精確到年月日
實體類
package com.pcmall.domain.sale.erps; import java.util.Date; public class Synnexlogs { private String sender; private String receiver; private Date calltime; private String inputparam; private String outputparam; private String type; private String remark; public String getSender() { return sender; } public void setSender(String sender) { this.sender = sender == null ? null : sender.trim(); } public String getReceiver() { return receiver; } public void setReceiver(String receiver) { this.receiver = receiver == null ? null : receiver.trim(); } public Date getCalltime() { return calltime; } public void setCalltime(Date calltime) { this.calltime = calltime; } public String getInputparam() { return inputparam; } public void setInputparam(String inputparam) { this.inputparam = inputparam == null ? null : inputparam.trim(); } public String getOutputparam() { return outputparam; } public void setOutputparam(String outputparam) { this.outputparam = outputparam == null ? null : outputparam.trim(); } public String getType() { return type; } public void setType(String type) { this.type = type == null ? null : type.trim(); } public String getRemark() { return remark; } public void setRemark(String remark) { this.remark = remark == null ? null : remark.trim(); } }
xml檔案
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="com.pcmall.dao.sale.erps.SynnexlogsMapper" > <resultMap id="BaseResultMap" type="com.pcmall.domain.sale.erps.Synnexlogs" > <result column="SENDER" property="sender" jdbcType="VARCHAR" /> <result column="RECEIVER" property="receiver" jdbcType="VARCHAR" /> <result column="CALLTIME" property="calltime" jdbcType="TIMESTAMP" /> <result column="INPUTPARAM" property="inputparam" jdbcType="VARCHAR" /> <result column="OUTPUTPARAM" property="outputparam" jdbcType="VARCHAR" /> <result column="TYPE" property="type" jdbcType="VARCHAR" /> <result column="REMARK" property="remark" jdbcType="VARCHAR" /> </resultMap> <insert id="insert" parameterType="com.pcmall.domain.sale.erps.Synnexlogs" > insert into SYNNEXLOGS (SENDER, RECEIVER, CALLTIME, INPUTPARAM, OUTPUTPARAM, TYPE, REMARK) values (#{sender,jdbcType=VARCHAR}, #{receiver,jdbcType=VARCHAR}, #{calltime,jdbcType=TIMESTAMP}, #{inputparam,jdbcType=VARCHAR}, #{outputparam,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}) </insert> <insert id="insertSelective" parameterType="com.pcmall.domain.sale.erps.Synnexlogs" > insert into SYNNEXLOGS <trim prefix="(" suffix=")" suffixOverrides="," > <if test="sender != null" > SENDER, </if> <if test="receiver != null" > RECEIVER, </if> <if test="calltime != null" > CALLTIME, </if> <if test="inputparam != null" > INPUTPARAM, </if> <if test="outputparam != null" > OUTPUTPARAM, </if> <if test="type != null" > TYPE, </if> <if test="remark != null" > REMARK, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides="," > <if test="sender != null" > #{sender,jdbcType=VARCHAR}, </if> <if test="receiver != null" > #{receiver,jdbcType=VARCHAR}, </if> <if test="calltime != null" > #{calltime,jdbcType=TIMESTAMP}, </if> <if test="inputparam != null" > #{inputparam,jdbcType=VARCHAR}, </if> <if test="outputparam != null" > #{outputparam,jdbcType=VARCHAR}, </if> <if test="type != null" > #{type,jdbcType=VARCHAR}, </if> <if test="remark != null" > #{remark,jdbcType=VARCHAR}, </if> </trim> </insert> </mapper>