多值傳參1
阿新 • • 發佈:2020-09-02
1、工具類
public class Datas { private List<Integer> ids = new ArrayList<Integer>(); public List<Integer> getIds() { return ids; } public void setIds(List<Integer> ids) { this.ids = ids; } }
前臺:
$("#assignBtn").click(function(){
console.log(roleId);
var json ={roleId:roleId};
var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
var nodes = treeObj.getCheckedNodes(true);
console.log("nodes={}",nodes);
$.each(nodes,function(i,e){
var permissionId = e.id;
console.log(permissionId);
json['ids['+i+'] '] = permissionId;
});
$.ajax({
type:"post",
url:"${PATH}/role/doAssignPermissionToRole",
data:json,
success:function(result){
if("ok" == result){
layer.msg("分配成功",{icon:6,time:1000},function(){
$("#assignModal").modal('hide');
});
}else{
layer.msg("分配失敗",{incon:5,time:1000});
}
}
});
});
後臺:
@ResponseBody @RequestMapping("/role/doAssignPermissionToRole") public String doAssignPermissionToRole(Integer roleId,Datas ds) { log.debug("roleId={}",roleId); log.debug("permissionId={}",ds.getIds()); rolerService.saveRoleAndPermissionRelationship(roleId,ds.getIds()); return "ok"; }