package com.testor.common.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.tongtech.tfw.backend.common.biz.models.BaseResponse;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/**
 * @author rsq
 * @program policy_query
 * @return
 **/
@Component
public class ResponseUtil {
    public static void write(HttpServletResponse response, String message, Integer code, boolean status) throws Exception {

        BaseResponse result = new BaseResponse();
        result.setCode(code);
        result.setMsg(message);
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json; charset=utf-8");
        PrintWriter out = response.getWriter();
        ObjectMapper objectMapper = new ObjectMapper();
        out.write(objectMapper.writeValueAsString(result));
        out.flush();
        out.close();
    }
}
