🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
**1. 把用户信息放入token、及使用介绍** * 用户信息放入:AuthorizationConfig @Bean public TokenEnhancer tokenEnhancer() { return (accessToken, authentication) -> { final Map<String, Object> additionalInfo = new HashMap<>(2); additionalInfo.put("license", SecurityConstants.MS_LICENSE); UserDetailsImpl user = (UserDetailsImpl) authentication.getUserAuthentication().getPrincipal(); if (user != null) { **additionalInfo.put("userId", user.getUserId());** } ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo); return accessToken; }; } * 根据请求heard中的token获取用户ID【BaseController】 /** *根据请求heard中的token获取用户ID *@return 用户ID */ public Integer getUserId() { return UserUtils.getUserId(request); } * 用户信息使用例子 [SysUserController] /** *@param params 用户信息 *@return */ @ApiOperation(value = "用户信息列表",notes = "多条件分页查询用户") @ApiImplicitParam(name = "SysUser",value = "SysUser",dataType = "R",paramType = "path") @RequestMapping("/userPage") public Page userPage(@RequestParam(required = false) Map<String, Object> params) { UserVO user = userService.findUserByMobile("15001875059"); System.out.println("通过Feign获取UPMS系统的用户名为:"+user.getUsername()); Integer userId = getUserId(); System.out.println(userId); params.put(CommonConstant.STATUS_FLAG,CommonConstant.STATUS_NORMAL); return sysUserService.selectByPage(new Query<>(params),new EntityWrapper<>()); }