我在用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 "-////DTD Mapper 3.0//EN" "/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>