From 8f0a3a1e8894617211b37e24ac0297dd5d9bd601 Mon Sep 17 00:00:00 2001
From: ZengTao <2773468879@qq.com>
Date: 星期五, 08 九月 2023 17:24:45 +0800
Subject: [PATCH] 主界面添加警报信息显示
---
springboot-vue3/src/main/java/com/example/springboot/component/WebSocketServer.java | 17 ++++++++++++++++-
1 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/WebSocketServer.java b/springboot-vue3/src/main/java/com/example/springboot/component/WebSocketServer.java
index 697d697..8749b5e 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/component/WebSocketServer.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/WebSocketServer.java
@@ -4,6 +4,8 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.catalina.core.ApplicationContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -16,8 +18,8 @@
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
+import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;
-
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
@@ -25,6 +27,17 @@
@ServerEndpoint(value = "/api/talk/{username}")
@Component
public class WebSocketServer {
+
+ // @Autowired
+ // HomeMapper homeMapper;
+
+ static ConfigurableApplicationContext applicationContext;
+
+ //瑙e喅鏃犳硶娉ㄥ叆mapper闂 //浣跨敤鏂规硶 homeMapper=WebSocketServer.applicationContext.getBean(HomeMapper.class);
+ public static void setApplicationContext(ConfigurableApplicationContext configurableApplicationContext) {
+ WebSocketServer.applicationContext = configurableApplicationContext;
+ }
+
private static final Logger log = LoggerFactory.getLogger(WebSocketServer.class);
private List<String> messages;
@@ -86,6 +99,7 @@
jsonObject.set("message", text);
this.messages.add(text);
this.sendMessage(jsonObject.toString()); //JSONUtil.toJsonStr(jsonObject)
+
}
@OnError
@@ -122,6 +136,7 @@
public List<String> getMessages() {
return messages;
+
}
public void clearMessages() {
--
Gitblit v1.8.0