package com.sckw.core.web.response;

import com.alibaba.fastjson.JSON;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * @desc 响应
 * @author zk
 * @date 2020/08/19
 */
public class ResponseUtil {

    /**
     * 相应输出
     * @param response 响应
     * @param httpResult 相应内容
     * @throws Exception
     */
    public static void writer(HttpServletResponse response, HttpResult httpResult) throws IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json;charset=UTF-8");
        PrintWriter printWriter = response.getWriter();
        printWriter.write(JSON.toJSONString(httpResult));
        printWriter.flush();
        printWriter.close();
    }
}
