Mapper批量插入Oracle数据@InsertProvider注解
Mapper:
@Mapper
@OracleRepository
public interface OracleRadiusMapper{
@InsertProvider(type = OracleRadiusProvider.class , method = "insertRadiusDataBatch")
int insertRadiusDataBatch(@Param("list")List<AcctInfo> acctInfoList);
}
//@Param("list") 可以省略,在处理list的时候默认是list
Provider:
public class OracleRadiusProvider {
public String insertRadiusDataBatch(Map map) {
List<RadiusAcctInfo> radiusAcctInfoList = (List<RadiusAcctInfo>) map.get("list");
StringBuilder sb = new StringBuilder();
sb.append(" INSERT ALL ");
String inVal=" INTO RADIUS_ACCT (RADACCT_ID,ACCT_SESSIONID,ACCT_UNIQUEID,USER_NAME,GROUP_NAME,REALM,NAS_IP_ADDRESS,NAS_PORT_ID,NAS_PORT_TYPE,ACCT_START_TIME,ACCT_UPDATE_TIME,ACCT_STOP_TIME,ACCT_INTERVAL,"
+ "ACCT_SESSION_TIME,ACCT_AUTHENTIC,CONNECTINFO_START,CONNECTINFO_STOP,ACCT_INPUTOCTETS,ACCT_OUTPUTOCTETS,CALLED_STATION_ID,CALLING_STATION_ID,ACCT_TERMINATE_CAUSE,SERVICE_TYPE,"
+ "FRAMED_PROTOCOL,FRAMED_IP_ADDRESS) VALUES";
sb.append(inVal);
MessageFormat mf = new MessageFormat("("
+ "#'{'list[{0}].radacctId,jdbcType=NUMERIC}, #'{'list[{0}].acctSessionid,jdbcType=VARCHAR}, #'{'list[{0}].acctUniqueid,jdbcType=VARCHAR}, #'{'list[{0}].userName,jdbcType=VARCHAR}"
+ ", #'{'list[{0}].groupName,jdbcType=VARCHAR}, #'{'list[{0}].realm,jdbcType=VARCHAR}, #'{'list[{0}].nasIpAddress,jdbcType=VARCHAR}, #'{'list[{0}].nasPortId,jdbcType=VARCHAR}, #'{'list[{0}].nasPortType,jdbcType=VARCHAR}"
+ ", #'{'list[{0}].acctStartTime,jdbcType=DATE}, #'{'list[{0}].acctUpdateTime,jdbcType=DATE}, #'{'list[{0}].acctStopTime,jdbcType=DATE}, #'{'list[{0}].acctInterval,jdbcType=NUMERIC}, #'{'list[{0}].acctSessionTime,jdbcType=NUMERIC}"
+ ", #'{'list[{0}].acctAuthentic,jdbcType=VARCHAR}, #'{'list[{0}].connectinfoStart,jdbcType=VARCHAR}, #'{'list[{0}].connectinfoStop,jdbcType=VARCHAR}, #'{'list[{0}].acctInputoctets,jdbcType=NUMERIC}, #'{'list[{0}].acctOutputoctets,jdbcType=NUMERIC}"
+ ", #'{'list[{0}].calledStationId,jdbcType=VARCHAR}, #'{'list[{0}].callingStationId,jdbcType=VARCHAR}, #'{'list[{0}].acctTerminateCause,jdbcType=VARCHAR}, #'{'list[{0}].setviceType,jdbcType=VARCHAR}, #'{'list[{0}].framedProtocol,jdbcType=VARCHAR}"
+ ", #'{'list[{0}].framedIpAddress,jdbcType=VARCHAR} )");
for (int i = 0; i < radiusAcctInfoList.size(); i++) {
sb.append(mf.format(new Object[] { i+"" }));
if (i < radiusAcctInfoList.size() - 1) {
sb.append(inVal);
}
}
sb.append(" select 1 from dual");//记得加这句
return sb.toString();
}
}
可以在数据库直接咨询这语句
insert all
into jack_20170206_aa values('4014033')
into jack_20170206_aa values('4065304')
into jack_20170206_aa values('4088136')
into jack_20170206_aa values('4092405')
select 1 from dual;
总结
以上是 Mapper批量插入Oracle数据@InsertProvider注解 的全部内容, 来源链接: utcz.com/z/312748.html