|
|
@@ -0,0 +1,26 @@
|
|
|
+package cn.tr.module.smart.app.controller;
|
|
|
+
|
|
|
+import cn.dev33.satoken.annotation.SaIgnore;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@SaIgnore
|
|
|
+public class SseController {
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ public void init(){
|
|
|
+ System.out.println("123");
|
|
|
+ }
|
|
|
+ @GetMapping(value = "/sse/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
|
|
+ public Stream<String> stream() {
|
|
|
+ // 模拟数据流
|
|
|
+ return Stream.generate(() -> "当前时间:" + LocalTime.now())
|
|
|
+ .limit(10); // 限制10条消息
|
|
|
+ }
|
|
|
+}
|