SSeEmitter返回类型附加数据:将被截断

时间:2018-07-04 15:43:47

标签: spring spring-boot angular6 server-sent-events

这是我在 WebController.java

中的rest方法
@GetMapping("/test")
    public  SseEmitter Test()
    {
        String x = "hgkgkjkgk";
        final SseEmitter emitter = new SseEmitter();
        emitters.add(emitter);
        emitter.onCompletion(() -> emitters.remove(emitter));

        try {
            emitter.send(x, MediaType.APPLICATION_JSON);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

          return emitter;
    } 

我从中得到结果的
    http://localhost:8080/api/test

  

data:hgkgkjkgk

但是我只需要结果

  

hgkgkjkgk

没有 数据: , 我面临的问题是,当将数据获取为json时,例如:

data:[
{"state":"Completed","mignum":146289,"projectleader":"Eric Lok"},
{"state":"Completed","mignum":146381,"projectleader":"James Rice"},
{"state":"Completed","mignum":146461,"projectleader":"Nishith Jani"},
{"state":"Completed","mignum":146574,"projectleader":"Nishith Jani"}]

由于 数据: ,我在Angular端处理时遇到困难。 谁能帮我,如何在Spring引导端或Angular端截断

0 个答案:

没有答案