1
zj
2024-07-15 3e94b30057748e7b89bf52185a98412882d8524e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package org.example.websocket.controller;
 
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.example.websocket.server.WsServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.lang.reflect.Type;
import java.util.Map;
 
/**
 * @program: webSocketProject
 * @description:
 * @create: 2024-03-26 16:55
 **/
@RestController
@RequestMapping("/api")
public class ReceptionController {
 
    @Autowired
    private WsServer wsServer;
 
    @PostMapping("/sendNotification")
    public void sendNotification(@RequestParam("message") String message) {
        try {
            // 全体发送
            wsServer.sendMessageToAll(message);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
}