shenyijian
2024-12-02 eed72349910ec181532e5f7ce13677788a769d21
skjcmanager/skjcmanager-service/skjcmanager-by/src/main/java/cn/gistack/by/nettyUpload/utils/HttpResponseUtils.java
@@ -9,6 +9,8 @@
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.util.CharsetUtil;
import java.util.Map;
import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
@@ -49,4 +51,18 @@
        ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
    }
   public static void sendResponseJson2(ChannelHandlerContext ctx, HttpResponseStatus status,
                               String message,Map<String, Object> map) {
      JSONObject jsonObject = new JSONObject();
      jsonObject.put("code", status.code());
      jsonObject.put("msg", message);
      jsonObject.put("data", map);
      FullHttpResponse response = new DefaultFullHttpResponse(
         HTTP_1_1, status, Unpooled.copiedBuffer(jsonObject.toJSONString(), CharsetUtil.UTF_8));
      response.headers().set(CONTENT_TYPE, "application/json; charset=UTF-8");
      ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
   }
}