@ResponseBody
@RequestMapping("updateRoles")
public List<HashMap> updateRoles(@RequestParam String info) {
//用于存放所有信息的HashMap
HashMap map = new HashMap();
//放入表名
map.put("tb_name", "test_for_sql");
//放入表的字段
List<String> cols = new ArrayList<>();
cols.add("id");
cols.add("name");
map.put("cols", cols);
//放入表中字段(id、name)对应的值
List<String[]> vals = new ArrayList<>();
vals.add(new String[]{"1","zs"});
vals.add(new String[]{"2","ls"});
vals.add(new String[]{"3","ww"});
map.put("vals", vals);
//执行批量插入
adminService.addPersForAdmin(map);
return null;
}
<insert id="addPersForAdmin" parameterType="HashMap">
insert into ${tb_name}(
<foreach collection="cols" item="col" separator=",">
${col}
</foreach>
)
values
<foreach collection="vals" item="val" separator=",">
(
<foreach collection="val" separator="," item="arr_val">
#{arr_val}
</foreach>
)
</foreach>
</insert>
insert into test_sql(id,name) values
("1","zs"),
("2","ls"),
("3","ww")
如有错,欢迎指正~~~
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- oldu.cn 版权所有 浙ICP备2024123271号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务