Controller层:
/**
* 添加用户
* @return
*/
@ApiOperation(value = "添加用户", notes = "添加用户")
@PostMapping("/addUser")
public R addUser(@RequestBody List<SysDeptLeader> deptLeader){
return R.ok(sysDeptService.addLeader(deptLeader));
}
/**
* 删除用户
* @return
*/
@ApiOperation(value = "删除用户", notes = "删除用户")
@DeleteMapping("/delUser")
public R editUser(@RequestBody List<SysDeptLeader> deptLeader){
return R.ok(sysDeptService.delLeader(deptLeader));
}
Impl层:
/**
*添加用户
* @Param deptLeader批量添加用户
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean addLeader(List<SysDeptLeader> deptLeader) {
for(int i=0; i < deptLeader.size() ; i++) {
try {
sysDeptLeaderMapper.saveBatch(deptLeader);
//sysDeptLeaderMapper.insert(deptLeader.get(i));
} catch (Exception e) {
System.out.println(e);
}
}
return Boolean.TRUE;
}
/**
*批量删除用户
* @Param deptLeader批量删除用户
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean delLeader(List<SysDeptLeader> deptLeader) {
try {
sysDeptLeaderMapper.deleteBatch(deptLeader);
//sysDeptLeaderMapper.deleteUser(deptLeader.get(i).getDeptId(),deptLeader.get(i).getUserId());
} catch (Exception e) {
System.out.println(e);
}
return Boolean.TRUE;
}
Mapper层,
<insert id="saveBatch">
insert into
sys_dept_leader(dept_id,leader,phone,position,user_id,major)
values
<foreach collection="list" separator="," item="item">
(#{item.deptId},#{item.leader},#{item.phone},#{item.position},#{item.userId},#{item.major})
</foreach>
</insert>
<delete id="deleteBatch">
delete from sys_dept_leader
where dept_id = #{deptId,jdbcType = INTEGER} and user_id in
<foreach collection="userId" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
</delete>