oracle+myBatis中使用foreach批量入库ok__插入Date:允许传入null和日期对象[java.util.Date]

2019-03-13 0935 星期三 enAn
oracle:myBatis中使用foreach批量入库–插入Date日期:允许传入null和日期对象[java.util.Date]入库成功
#{item.id , javaType=string, jdbcType=VARCHAR},<%-- 实体是String型,数据为varchar2 %–>
#{item.rateType , javaType=int, jdbcType=NUMERIC},<%-- 实体是int型,数据为number %–>
#{item.effectiveDate , jdbcType=TIMESTAMP},
在这里插入代码片

<?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.xxx.ccccc.platform.wsdl.service.impl.FDPReportRateServiceImpl">

	<!-- esb汇率数据[FDPReportRateService][主数据发布汇率数据服务],2019-03-12 -->
	<insert id="saveEsbData" parameterType="map">
		<foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
		insert into hfmadp_reportrate  (id,source,base_currency,quote_currency,exchange_rate,rate_type,status,remark,
					effective_date,create_time,update_time,last_update_date,creation_date,
					batch_id,create_by,update_by,created_by,last_updated_by) 
 		values(
 			#{item.id ,				javaType=string,	jdbcType=VARCHAR},<!-- 实体是String型,数据为varchar2 -->
 			#{item.source ,			javaType=string,	jdbcType=VARCHAR},
 			#{item.baseCurrency ,	javaType=string,	jdbcType=VARCHAR},
 			#{item.quoteCurrency ,	javaType=string,	jdbcType=VARCHAR},
 			#{item.exchangeRate ,	javaType=string,	jdbcType=VARCHAR},
 			#{item.rateType ,		javaType=int, 		jdbcType=NUMERIC},<!-- 实体是int型,数据为number -->
 			#{item.status ,			javaType=int, 		jdbcType=NUMERIC},
 			#{item.remark ,			javaType=string,	jdbcType=VARCHAR},
 			<!-- 3 -->
 			<!-- 特别说明:允许传入null和日期对象[java.util.Date],入库成功,2019-03-12,begin -->
 			#{item.effectiveDate ,						jdbcType=TIMESTAMP},
 			#{item.createTime ,							jdbcType=TIMESTAMP},
 			#{item.updateTime ,							jdbcType=TIMESTAMP},
 			#{item.lastUpdateDate ,						jdbcType=TIMESTAMP},
 			#{item.creationDate ,						jdbcType=TIMESTAMP},
 			<!-- 特别说明:允许传入null和日期对象[java.util.Date],入库成功,2019-03-12,end -->
 			<!-- 4 -->
 			#{item.batchId ,		javaType=string,	jdbcType=VARCHAR},
 			#{item.createBy ,		javaType=string,	jdbcType=VARCHAR},
 			#{item.updateBy ,		javaType=string,	jdbcType=VARCHAR},
 			#{item.createdBy ,		javaType=string,	jdbcType=VARCHAR},
 			#{item.lastUpdatedBy ,	javaType=string,	jdbcType=VARCHAR}
		)
 		</foreach>
	</insert>
</mapper>

对应实现xxxxxxServicesImpl.java

	/**
	 * 订阅消息入库
	 * @param batchId 批次号
	 * @param list 实体list
	 * @return
	 * @author enAn
	 * @date 2019-03-12
	 */
	@Override
	public int saveData(String batchId,List<HfmadpReportrateEntity> list){
		Map<String,Object> paramMap = new HashMap<String, Object>();
		paramMap.put("batchId", batchId);//批次号
		int total= list.size();  //总记录数
		int pageSize = 50;  //每页显示的记录数,每批次数
		int totalPage= ((total%pageSize==0) ? (total/pageSize) : (total/pageSize+1)); //页数,总批次
		Date systemDate = new Date();
		log.info("{batchId:" + batchId + "},:总记录数{" + total + "},每批次数{"+pageSize+"},总批次{" + totalPage + "}");
		for (int currentPage = 1; currentPage <= totalPage; currentPage++) {
	    	int fromIndex = pageSize*(currentPage-1);
	    	int toIndex = (currentPage-1) * pageSize + pageSize;
	    	if(toIndex > total){
	    		toIndex = total;
	    	}
	    	Date beginDate = new Date();
			paramMap.put("list", list.subList(fromIndex,  toIndex));
			int result =  this.createByStatement("saveEsbData",paramMap);
			Date endDate = new Date();
			log.info("{" + batchId + "},分批,当前次数/总次数{" + currentPage + "/" + totalPage + "},end,插入结果{" + result + "}"
					+ ",每批次数/总数{" + pageSize + "/" + total+ "}"
					+ ",开始/结束{" + fromIndex + "/" + toIndex +"}"
					+ ",开始时间/结束时间{" + formageDate(beginDate) + "},{" + formageDate(endDate) + "}"
					+ ",秒{" + (endDate.getTime()-beginDate.getTime())/1000 + "}");
			if(result!=-1){
				throw new RuntimeException("入库失败");
			}
		}
		Date endDate = new Date();
		log.info("{batchId:" + batchId + "},总耗时"
				+ ",开始时间{" +  formageDate(systemDate)+ "},结束时间{" + formageDate(endDate) + "}"
				+ ",相差秒数{" + (endDate.getTime()-systemDate.getTime())/1000 + "}");
		return 0;
	}

对应实现对象

public class HfmadpReportrateEntity implements java.io.Serializable {
	private static final long serialVersionUID = -4463700862475717228L;
    private String id;
    private String source;
    private String baseCurrency;
    private String quoteCurrency;
    private String exchangeRate;
    private Date effectiveDate;
    private int rateType;
    private int status;
    private String remark;
    private String createBy;
    private Date createTime;
    private String updateBy;
    private Date updateTime;
    //**********以下是主动加上标准字段**************************
    private String batchId;
    private String lastUpdatedBy;
    private Date lastUpdateDate;
    private String createdBy;
    private Date creationDate;
    
	@Override
	public String toString() {
		return "HfmadpReportrateEntity [id=" + id + ", source=" + source
				+ ", baseCurrency=" + baseCurrency + ", quoteCurrency="
				+ quoteCurrency + ", exchangeRate=" + exchangeRate
				+ ", effectiveDate=" + effectiveDate + ", rateType=" + rateType
				+ ", status=" + status + ", remark=" + remark + ", createBy="
				+ createBy + ", createTime=" + createTime + ", updateBy="
				+ updateBy + ", updateTime=" + updateTime + ", batchId="
				+ batchId + ", lastUpdatedBy=" + lastUpdatedBy
				+ ", lastUpdateDate=" + lastUpdateDate + ", createdBy="
				+ createdBy + ", creationDate=" + creationDate + "]";
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getSource() {
		return source;
	}
	public void setSource(String source) {
		this.source = source;
	}
	public String getBaseCurrency() {
		return baseCurrency;
	}
	public void setBaseCurrency(String baseCurrency) {
		this.baseCurrency = baseCurrency;
	}
	public String getQuoteCurrency() {
		return quoteCurrency;
	}
	public void setQuoteCurrency(String quoteCurrency) {
		this.quoteCurrency = quoteCurrency;
	}
	public String getExchangeRate() {
		return exchangeRate;
	}
	public void setExchangeRate(String exchangeRate) {
		this.exchangeRate = exchangeRate;
	}
	public Date getEffectiveDate() {
		return effectiveDate;
	}
	public void setEffectiveDate(Date effectiveDate) {
		this.effectiveDate = effectiveDate;
	}
	public int getRateType() {
		return rateType;
	}
	public void setRateType(int rateType) {
		this.rateType = rateType;
	}
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	public String getCreateBy() {
		return createBy;
	}
	public void setCreateBy(String createBy) {
		this.createBy = createBy;
	}
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	public String getUpdateBy() {
		return updateBy;
	}
	public void setUpdateBy(String updateBy) {
		this.updateBy = updateBy;
	}
	public Date getUpdateTime() {
		return updateTime;
	}
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	public String getBatchId() {
		return batchId;
	}
	public void setBatchId(String batchId) {
		this.batchId = batchId;
	}
	public String getLastUpdatedBy() {
		return lastUpdatedBy;
	}
	public void setLastUpdatedBy(String lastUpdatedBy) {
		this.lastUpdatedBy = lastUpdatedBy;
	}
	public Date getLastUpdateDate() {
		return lastUpdateDate;
	}
	public void setLastUpdateDate(Date lastUpdateDate) {
		this.lastUpdateDate = lastUpdateDate;
	}
	public String getCreatedBy() {
		return createdBy;
	}
	public void setCreatedBy(String createdBy) {
		this.createdBy = createdBy;
	}
	public Date getCreationDate() {
		return creationDate;
	}
	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}
    
    
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值