java 获取token

/**
* 获取当前登录用户id
*
* @return
*/
public Long getCurrentUserIdByToken() {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = servletRequestAttributes.getRequest();
String userName = JwtUtil.getUserNameByToken(request);

    LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(DataUserEntity::getUserName, userName).eq(DataUserEntity::getIsDelete, 0);

    DataUserEntity userEntity = userDao.selectOne(queryWrapper);
    if (userEntity == null) {
        return null;
    }
    return userEntity.getId();
}

你可能感兴趣的:(java,spring,servlet)