链接:插件集成 | RuoYi
WebSocketServer.java:补充代码
/*** 此为广播消息* @param message 消息内容*/public void sendAllMessage(String message) {LOGGER.info("【websocket.sendAllMessage】广播消息:"+message);try {for(String sessionId : WebSocketUsers.getUsers().keySet()) {Session session = WebSocketUsers.getUsers().get(sessionId);WebSocketUsers.sendMessageToUserByText(session, message);}} catch (Exception e) {e.printStackTrace();}}/*** 此为单点消息* @param userId 用户编号* @param message 消息内容*/public void sendOneMessage(String sessionId, String message) {try {Session session = WebSocketUsers.getUsers().get(sessionId);if (session != null && session.isOpen()) {LOGGER.info("【websocket.sendOneMessage】 单点消息:"+message);WebSocketUsers.sendMessageToUserByText(session, message);}} catch (Exception e) {e.printStackTrace();}}/*** 此为单点消息(多人)* @param userIds 用户编号组* @param message 消息内容*/public void sendMoreMessage(String sessionIds, String message) {try {String[] sids = sessionIds.split(",");for(String sessionId : sids) {Session session = WebSocketUsers.getUsers().get(sessionId);if (session != null && session.isOpen()) {LOGGER.info("【websocket.sendMoreMessage】 多人消息:"+message);WebSocketUsers.sendMessageToUserByText(session, message);}}} catch (Exception e) {e.printStackTrace();}}
.antMatchers("/websocket/**", "/test/**").permitAll()