日期:2014-05-16  浏览次数:20576 次

dao中向数据库中插入一堆数据(ibatis)

这里的方法只对使用了ibatis框架的有效

dao方法:

public void insertSalaryBudget(List<SalaryBudgetTo> salaryBudgetList) {
		
		final List<SalaryBudgetTo> tmpList = salaryBudgetList;
		this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
			public Object doInSqlMapClient(SqlMapExecutor executor)
					throws SQLException {
				executor.startBatch();
				for (SalaryBudgetTo obj : tmpList) {
					if(obj!=null){
						Long userId=UserUtil.getUserId();
						String user="-1";
						if(userId!=null){
							user=userId.toString();
						}
						obj.setCreateBy(user);
						obj.setCreateDt(new Date());
						obj.setUpdateBy(user);
						obj.setUpdateDt(new Date());
						obj.setActByType("B");
						executor.insert("salary.insertSalaryBudget", obj);
					}
				}
				executor.executeBatch();
				return null;
			}
		});
	}

?ibatis中sqlmaps配置:

<insert id="salary.insertSalaryBudget" parameterClass="salaryBudgetTo">
		   INSERT INTO xc.tb_salary_budget(
			   pk,
			   slry_month,
			   user_id,
			   bus_type,
			   bus_child_type,
			   amount,
			   del_flag,
			   create_by,
			   create_dt,
			   update_dt,
			   update_by,
			   delete_by,
			   act_by_type
		   ) VALUES(
			   XC.XC_SQ_SALARY_BUDGET.nextval,
			   #slryMonth#,
			   #userId#,
			   #busType#,
			   #busChildType#,
			   #amount#,
			   1,
			   #createBy#,
			   #createDt#,
			   #updateDt#,
			   #updateBy#,
			   #deleteBy#,
			   #actByType#
		   )
	</insert>
?

?

?

?