java语言简单实现角色添加

rolemapper.xml

select roleId from user_role where userId=#{userId} select * from tb_role WHERE id NOT IN (SELECT roleId FROM user_role WHERE userId=#{id})

RoleService

@Service
public class RoleService implements IRoleService {

@Autowired
private RoleDao roleDao;
@Override
public List<Integer> findRoleId(int userId) {
    return roleDao.findRoleIdByUserId(userId);
}

@Override
public List<Role> findRoleByUserId(int id) {
    return roleDao.findRoleByUserId(id);
}

IRoleService

public interface IRoleService {
List findRoleId(int userId);

List<Role> findRoleByUserId(int id);

}

RoleDao

public interface RoleDao {
List findRoleIdByUserId(int userId);

List<Role> findRoleByUserId(int id);

}

toaddrole

@RequestMapping(“toAddRole.do”)
public ModelAndView toAddRole(int id){
List roleList=roleService.findRoleByUserId(id);
ModelAndView mv=new ModelAndView();
mv.addObject(“roleList”,roleList);
mv.setViewName(“user-role-add”);
return mv;

}

Role

package com.zhongruan.bean;

public class Role {
private int id;
private String rolename;
private String roledesc;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getRolename() {
    return rolename;
}

public void setRolename(String rolename) {
    this.rolename = rolename;
}

public String getRoledesc() {
    return roledesc;
}

public void setRoledesc(String roledesc) {
    this.roledesc = roledesc;
}

@Override
public String toString() {
    return "Role{" +
            "id=" + id +
            ", rolename='" + rolename + '\'' +
            ", roledesc='" + roledesc + '\'' +
            '}';
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值