需求:要求传入一个list集合到一个不固定的表中。参数为:表名和list集合
service层impl:
@Override
public int insertSummaryByList(String tablename, List<Map<String, String>> list) {
return summaryDao.insertSummaryByList(tablename, list);
}
dao层:
Integer insertSummaryByList(@Param("tablename") String tablename, @Param("list") List<Map<String, String>> list);
mapping.xml:
<insert id="insertSummaryByList">
insert into ${tablename} (sid,sCode,sDate)
<foreach close=")" collection="list" item="item" index="index"
open="(" separator="union">
select
'${item.sid}','${item.sCode}','${item.sDate}'
from dual
</foreach>
</insert>