春风项目四线(合箱线、总装线)
wujian
2024-03-16 059083082a6d284821b70eb7bb6805763014c402
提交 | 用户 | 时间
059083 1 package com.jcdm.main.websocket;
W 2
3 import org.springframework.stereotype.Controller;
4 import org.springframework.web.bind.annotation.GetMapping;
5 import org.springframework.web.bind.annotation.PathVariable;
6 import org.springframework.web.bind.annotation.RequestMapping;
7 import org.springframework.web.bind.annotation.ResponseBody;
8 import org.springframework.web.servlet.ModelAndView;
9
10 import java.io.IOException;
11 import java.util.HashMap;
12 import java.util.Map;
13
14 @Controller("web_Scoket_system")
15 @RequestMapping("/api/socket")
16 public class SystemController {
17
18     //页面请求
19     @GetMapping("/index/{userId}")
20     public ModelAndView socket(@PathVariable String userId) {
21         ModelAndView mav = new ModelAndView("/socket1");
22         mav.addObject("userId", userId);
23         return mav;
24     }
25
26     //推送数据接口
27     @ResponseBody
28     @RequestMapping("/socket/push/{cid}")
29     public Map pushToWeb(@PathVariable String cid, String message) {
30         Map<String,Object> result = new HashMap<>();
31         try {
32             WebSocketServer.sendInfo(message, cid);
33             result.put("code", cid);
34             result.put("msg", message);
35         } catch (IOException e) {
36             e.printStackTrace();
37         }
38         return result;
39     }
40
41
42
43
44 }