Java通过mybatis插入Oracle数据库中Date格式不显示到时分秒问题

我在用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>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值