wang
2024-04-18 b612510f2479cc7fc04fbf9c4982742bee9e2ceb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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();
        }
    }
}