spring 中 Response 异步返回 接口

springMVC或者SpringBoot业务代码开发时,有时候接到请求需要立刻返回数据,然后在继续业务;现在有一种方案可以实现同时不丢失用户信息,核心代码如下:

ServletOutputStream out = response.getOutputStream();
        JSONObject resultmap = new JSONObject();
        resultmap.put("result", "1212");
        byte[] resultBytes = resultmap.toString().getBytes();//二进制转化
        out.write(resultBytes);//返回客户端
        out.close();//关闭流,切记!

测试代码如下 比如:
 

 就这么简单易用!

猜你喜欢

转载自blog.csdn.net/nandao158/article/details/108540884