SELECT * FROM xc_menu WHERE id IN(
SELECT menu_id FROM xc_permission WHERE role_id IN(
SELECT role_id FROM xc_user_role WHERE user_id = '49'
)
)
@GetMapping("/getuserext")
public XcUserExt getUserext(@RequestParam("username") String username);
@Mapper
public interface XcMenuMapper {
public List<XcMenu> selectPermissionByUserId(String userid);
}
<?xml version="1.0" encoding="UTF‐8" ?>
<!DOCTYPE mapper PUBLIC "‐//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis‐3‐
mapper.dtd" >
<mapper namespace="com.xuecheng.ucenter.dao.XcMenuMapper" >
<select id="selectPermissionByUserId"
resultType="com.xuecheng.framework.domain.ucenter.XcMenu" parameterType="java.lang.String" >
SELECT
id,
CODE,
p_id pId,
menu_name menuName,
url,
is_menu isMenu,
LEVEL,
sort,
STATUS,
icon,
create_time createTime,
update_time updateTiem
FROM
xc_menu
WHERE id IN(
SELECT menu_id FROM xc_permission WHERE role_id IN(
SELECT role_id FROM xc_user_role WHERE user_id = #{id}
)
)
</select>
</mapper>
//根据账号查询用户的信息,返回用户扩展信息
public XcUserExt getUserExt(String username){
XcUser xcUser = this.findXcUserByUsername(username);
if(xcUser == null){
return null;
}
//根据用户id查询用户权限
String userId = xcUser.getId();
List<XcMenu> xcMenus = xcMenuMapper.selectPermissionByUserId(userId);
XcUserExt xcUserExt = new XcUserExt();
BeanUtils.copyProperties(xcUser,xcUserExt);
//用户的权限
xcUserExt.setPermissions(xcMenus);
return xcUserExt;
}
......
//请求ucenter查询用户
XcUserExt userext = userClient.getUserext(username);
if(userext == null){
//返回NULL表示用户不存在,Spring Security会抛出异常
return null;
}
//从数据库查询用户正确的密码,Spring Security会去比对输入密码的正确性
String password = userext.getPassword();
//指定用户的权限,这里暂时硬编码
List<String> permissionList = new ArrayList<>();
// permissionList.add("course_get_baseinfo");
// permissionList.add("course_find_pic");
//取出用户权限
List<XcMenu> permissions = userext.getPermissions();
for(XcMenu xcMenu:permissions){
permissionList.add(xcMenu.getCode());
}
......
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |