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 + '\'' +
'}';
}
}