springboot websocket带参数

java 后台:

@OnOpen
    public void onOpen(Session session, @PathParam("id") long id, @PathParam("name") String name) throws Exception {
        this.session = session;
        System.out.println(this.session.getId());
        webSocketSet.add(this);
        LOGGER.info("Open a websocket. id={}, name={}", id, name);
    }

 

Js前端:

// 通过路径传递参数的方法(服务端采用第一种方法"@ServerEndpoint"实现)
        websocket = new WebSocket("ws://127.0.0.1:18080/testWebsocket/23/Lebron");

 

 

 

 

 

参考:

https://www.cnblogs.com/strugglion/p/10021173.html

你可能感兴趣的:(springboot websocket带参数)