设置分配用户组时报错
<insert id="attachGroupToUser">
insert into t_user_group(user_id, group_id) value(#{uid},#{gid})
</insert>
这里uid找不到Parameter 'uid' not found. Available parameters are [arg1, arg0, param1, param2]
@Override
public int setGroups(Integer userId, List<Integer> groupIds) {
userMapper.deleteUserGroupAllocation(userId);
for (Integer groupId : groupIds){
userMapper.attachGroupToUser(userId,groupId);
}
return 0;
}
$('.allocation').click(function () {
let userId = $("#allc_id").val();
var groupIds = [];
let checks = $treeview.treeview('getChecked');
console.log(checks);
$.each(checks, function (index, item) {
if (item.parentId!==undefined) {
console.log(item.tags);
groupIds.push(item.tags);
}
});
// s = JSON.stringify(s);
if (groupIds.length < 1) {
alert("至少选择一个");
} else {
let result = {userId: userId,groupIds: groupIds};
console.log(result);
if (confirm("确定添加这些数据么")) {
alert("添加数据:" + result);
// window.location.reload();
//ajax发送异步请求
$.ajax({
url: "/owep/user/adminList/treeCheck_edit",
method: "post",
data: JSON.stringify(result),
dataType: "text",
async: false,
contentType: "application/json",
success: function (data) {
/!*重新加载本页面*!/
window.location.reload();
alert(data);
},
error: function (jqXRH) {
console.log(jqXRH);
alert("设置未同步")
}
})
}
}
console.log("分配,提交。");
//$('#form_allocation').submit();
});
let $treeview = $('#treeview_allocation');
function getTreeView() {
let url = "/owep/user/adminList/treeCheck";
let id = $("#allc_id").val();
initCheckTree($treeview, url,id);
}
这里alert("添加数据:" + result);值获取到的都是“添加数据:[object Object]”
/***
* @By Artherine
* @For 修改 对应用户的 用户-用户组 关系
* @param userGroupDTO
* @return msg
*/
@PostMapping(value = "/adminList/treeCheck_edit")
@ResponseBody
public Object postTreeCheckEdit(@RequestBody UserGroupDTO userGroupDTO) {
System.out.println("U-G dto: " + userGroupDTO);
Integer userId = userGroupDTO.getUserId();
List<Integer> groupIds = userGroupDTO.getGroupIds();
userService.setGroups(userId, groupIds);
String result = "success";
return result;
}
/***
* @By Artherine
* @For 为前端提供用户组多选框表 并预设当前用户的用户组关系
* @param userId
* @return NodeDTO(..., List < NodeDTO > nodes)
*/
@GetMapping(value = "/adminList/treeCheck", produces = "application/json")
@ResponseBody
public Object getTreeCheckData(@RequestParam("id") Integer userId) {
System.out.println("试着二=========================================");
System.out.println("User manager adminList get Tree&Check Data");
{//数据库数据
List<GroupDTO> groupDTOS = groupService.selectAllGroups(0);//从库中获得所有对象
List<Integer> groupIds = userService.getGroupIds(userId);//查询用户之前归属的用户组id
List<NodeDTO> nodes = new ArrayList<>();
for (GroupDTO group : groupDTOS) {//封装为NodeDTO
NodeDTO subNode = new NodeDTO();
Integer groupId = group.getId();
subNode.setTags(groupId);
subNode.setText(group.getGroupName());
if (groupIds.contains(groupId)) {//id在记录列表中则激活此节点
subNode.nodeChecked();
}
nodes.add(subNode);//节点入列
}
NodeDTO topNode = new NodeDTO();//把用户组节点包装在一个父节点下
topNode.setTags(0);
topNode.setText("用户组");
topNode.setNodes(nodes);
NodeDTO[] nodeArr = new NodeDTO[1];
nodeArr[0] = topNode;
System.out.println("用户组节点树和状态:" + nodeArr[0]);//
return nodeArr;
}
}
难住了,求详解