欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-02-26 10:06:16
mapper: @mapper @oraclerepository public interface oracleradiusmapper{ @insert...

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;

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接