注意點(diǎn)
1.mapper內(nèi)參數(shù) 是復(fù)制的導(dǎo)致復(fù)制出錯(cuò) 查了好久
2.list.get(i) list 使用.get(i) 還是基礎(chǔ)太差
3.確定結(jié)構(gòu) 所有查詢 只和mapper有關(guān)mapper 值處理對應(yīng)表查詢
controller 只處理 接口 返回對象
其余都放到service
基本 遇到的問題都獨(dú)立解決了 很多新手錯(cuò)誤 但是都能自己解決
差熟練度而已
實(shí)現(xiàn)中 有些 需要 思考的
這里應(yīng)該哦是事務(wù)提交才對 比如這個(gè)
1.3 重疊注意
1.SysRoleController
@GetMapping(value = "/findAllRoles/{userId}")
public Result findAllRoles(@PathVariable(value = "userId") Long userId) {
Map map = sysAssignService.findAllRoles(userId);
return Result.build(map , ResultCodeEnum.SUCCESS) ;
}
2.service
/**
查詢角色列表
* */
List<SysRole> findAllRoles();
2.1 service Impl
@Override
public Map findAllRoles(Long userId) {
List<SysRole> sysRoleList = sysRoleMapper.findAllRoles();
List<Long> roleIds = sysAssignMapper.findAllRoles(userId);
Map map = new HashMap();
map.put("allRolesList",sysRoleList);
map.put("sysUserRoles",roleIds);
return map;
}
3.mapper
SysRoleMapper
/**
查詢角色列表
* */
List<SysRole> findAllRoles();
SysAssignMapper
List<Long> findAllRoles(Long user_id);
3.mapper。xml
SysRoleMapper
<select id="findAllRoles" resultType="com.atguigu.spzx.model.entity.system.SysRole">
select <include refid="columns"/> from sys_role where is_deleted =0;
</select>
SysAssignMapper
<select id="findAllRoles" resultType="long">
select role_id from sys_user_role where user_id = #{ user_id };
</select>
2.用戶提交數(shù)據(jù)角色
1缀壤。Controller
/***
//保存分配數(shù)據(jù) 存在第三張表中
/
@PostMapping("/doAssign")
public Result doAssign(@RequestBody AssginRoleDto assginRoleDto) {
int row = sysAssignService.doAssign(assginRoleDto);
if(row == 0){
return Result.build(assginRoleDto,ResultCodeEnum.INSERT_FAILL);
}else {
return Result.build(assginRoleDto,ResultCodeEnum.SUCCESS);
}
}
2.service
int doAssign(AssginRoleDto assginRoleDto);
2攻谁。1.serviceImpl
/*
這里應(yīng)該哦是事務(wù)提交才對
* */
@Override
public int doAssign(AssginRoleDto assginRoleDto) {
int srow = 0;
for (int i = 0 ;i<assginRoleDto.getRoleIdList().size();i++){
List<Long> list = assginRoleDto.getRoleIdList();
Long role_id = list.get(i);
int row = sysAssignMapper.insert(role_id,assginRoleDto.getUserId());
srow = row+srow;
}
return srow;
}
3mapper
int insert(Long role_id, Long user_id);
3.1mapper。xml
<insert id="insert">
insert into sys_user_role(user_id , role_id,create_time , update_time , is_deleted)
values(#{user_id},#{role_id},now() , now() , 0)
</insert>