Giter Site home page Giter Site logo

Comments (3)

coder-xiaomo avatar coder-xiaomo commented on June 3, 2024

可能我提问中的 Stream 方式不太容易理解,我将其简化为如下 for 循环方式,两种方式应该是等效的,都能够说明问题

    public List<String> getCurrentUserLoginPlatform() {
        // 获取当前登录账号的ID
        Object loginId = StpUtil.getLoginId();

        // 获取该账号的所有设备的Token Value
        List<String> tokenValues = StpUtil.getTokenValueListByLoginId(loginId);

        ArrayList<String> deviceList = new ArrayList<>();

        // 遍历所有Token Value
        for (String tokenValue : tokenValues) {
            // 通过Token Value获取Session信息
            SaSession tokenSession = StpUtil.getTokenSessionByToken(tokenValue);
            if (tokenSession != null) {
                // 获取 session 的 dataMap
                Map<String, Object> dataMap = tokenSession.getDataMap();

                // 获取 dataMap 中保存的 device 字段(登录时写入)
                String device = dataMap.getOrDefault("device", "未知设备").toString();
                deviceList.add(device);
            }
        }
        return deviceList;
    }

image

from sa-token.

ly-chn avatar ly-chn commented on June 3, 2024

写的有点麻烦, 我大致写一个你先看看行不行, 稍后我再看看你的代码

        Set<String> currentUserLoginDevices = StpUtil.getSession()
                .getTokenSignList()
                .stream().map(TokenSign::getDevice)
                .collect(Collectors.toSet());

from sa-token.

coder-xiaomo avatar coder-xiaomo commented on June 3, 2024

写的有点麻烦, 我大致写一个你先看看行不行, 稍后我再看看你的代码 ...

谢谢,可以获取到了!原来是这样实现的😂

看来是我的打开方式不对,没注意到TokenSign::getDevice这个方法哈哈哈,再次感谢!

from sa-token.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.