Mybatis里面:
insert into USER_ROLE_AUT
(RU_ID, RU_ROLE_ID, RU_AUT_ID, RU_TIME_INS, RU_USER_INS, RU_TIME_LST, RU_USER_LST, RU_STATUS)
select U.* from USER_ROLE_AUT
( <foreach collection="maps" item="item" index="index" separator="union all" >
select
RU_ID_SEQ.Nextval,
#{item.ruRoleId,jdbcType=DECIMAL},
#{item.ruAutId,jdbcType=DECIMAL},
#{item.ruTimeIns,jdbcType=TIMESTAMP},
#{item.ruUserIns,jdbcType=VARCHAR},
#{item.ruTimeLst,jdbcType=TIMESTAMP},
#{item.ruUserLst,jdbcType=VARCHAR},
#{item.ruStatus,jdbcType=CHAR}
from USER_ROLE_AUT
</foreach>
)U
action里面:
@RequestMapping("roleAutSave")
@ResponseBody
public Map roleAutSave(HttpServletRequest request, HttpSession session)
throws SystemException {
Map<String, Object> rtnmap = null;
Map<String, Object> map = new HashMap<String, Object>();
try {
String ruAutId = request.getParameter("ruAutId");// 获取到树形菜单选中的节点
System.out.println(ruAutId);
String[] adeArrs = ruAutId.split(",");
System.out.println(adeArrs);
String ruRoleId = request.getParameter("ruRoleId");// 获取选中的角色id
String ruUserIns = request.getParameter("ruUserIns");// 获取登录的账号
List<UserRoleAut> ls = new ArrayList<UserRoleAut>();
UserRoleAut ur = null;
for (String ade : adeArrs) {
ur = new UserRoleAut();
ur.setRuRoleId(new Long(ruRoleId));
ur.setRuAutId(new Long(ade));
ur.setRuUserIns(ruUserIns);
ls.add(ur);
}
map.put("maps", ls);
userRoleAutMapper.insert(map);// 保存
userRoleAutMapper.deleteByPrimaryKey();
rtnmap = okMap("roleAut");
} catch (Exception e) {
rtnmap = failMap("roleAut");
e.printStackTrace();
}
return rtnmap;
}