首页 > 开发 > Java > 正文

Mapper批量插入Oracle数据@InsertProvider注解

2024-07-14 08:43:32
字体:
来源:转载
供稿:网友

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;

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对VeVb武林网的支持。


注:相关教程知识阅读请移步到JAVA教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表