zhoushihao
2024-04-18 58dc9fa8de7b66ef375aa191da873813cbfae009
hangzhoumesParent/common/servicebase/src/main/java/com/mes/utils/ResponseUtil.java
New file
@@ -0,0 +1,28 @@
package com.mes.utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.HttpStatus;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * @Author : zhoush
 * @Date: 2024/4/8 15:46
 * @Description:
 */
public class ResponseUtil {
    public static final String APPLICATION_JSON_UTF8_VALUE = "application/json;charset=UTF-8";
    public static void out(HttpServletResponse response, Result r) {
        ObjectMapper mapper = new ObjectMapper();
        response.setStatus(HttpStatus.OK.value());
        response.setContentType(APPLICATION_JSON_UTF8_VALUE);
        try {
            mapper.writeValue(response.getWriter(), r);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}