1. 程式人生 > >ibaits數組形式批量入庫

ibaits數組形式批量入庫

into next get dds [] false int mce substring

一.xml層

<!--批量入庫-->
<insert id="addSecCodeList" parameterClass="java.util.HashMap">
<![CDATA[
BEGIN
]]>
<iterate property="secCodeList">
INSERT
INTO A_TABLE A
(
A.ID,
A.SECURITYNO,
A.BATCHNO,
A.ISDELETE
)
VALUES
(SEQ_SEC.nextval,#secCodeList[]#,#batchNo#,‘0‘);
</iterate>
<![CDATA[
END;
]]>
</insert>

二.action層

//批量生成
for (int i = 0; i < num; i++) {
sb.append(scu.createSecCode(productNo));
sb.append(",");
System.out.println("i="+i);
}
String securityNo = sb.toString();
securityNo=securityNo.substring(0,securityNo.length() -1);

//ibatis批量入庫
Map<String, Object> mapList=new HashMap<String, Object>();
mapList.put("securityNo", securityNo);
mapList.put("batchNo", batchNo);
batchService.addSecCodeList(mapList);

三.serviceImpl層

/**
*批量入庫
*/
public String addSecCodeList(Map<String, Object> map){
String securityNo=ConvertUtils.obj2Str(map.get("securityNo"),"");
String [] sn=securityNo.split(",");
map.put("secCodeList", sn);
return batchDao.addSecCodeList(map);
}

四.daoImpl層

/**

*批量入庫
*/
public String addSecCodeList(Map<String, Object> map){
try {
super.getSqlMapClientTemplate().insert("addSecCodeList", map);
return "true";
} catch (DataAccessException e) {
e.printStackTrace();
return "false";
}
}

ibaits數組形式批量入庫