WebSocketController.java 955 B

12345678910111213141516171819202122232425262728293031
  1. package top.haijunit.train.controller;
  2. import top.haijunit.train.websocket.WebSocketServer;
  3. import org.springframework.http.ResponseEntity;
  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.RestController;
  8. import org.springframework.web.servlet.ModelAndView;
  9. /**
  10. * @author zhanghaijun
  11. * @date 2023/11/3 16:36
  12. * @description 测试websocket界面
  13. */
  14. @RestController
  15. public class WebSocketController {
  16. @GetMapping("/page")
  17. public ModelAndView page() {
  18. return new ModelAndView("webSocket");
  19. }
  20. @RequestMapping("/push/{toUID}")
  21. public ResponseEntity<String> pushToClient(String message, @PathVariable String toUID) throws Exception {
  22. WebSocketServer.sendInfo(message, toUID);
  23. return ResponseEntity.ok("Send Success!");
  24. }
  25. }