ServletUtils.java 626 B

1234567891011121314151617181920212223
  1. package cn.iocoder.dashboard.util.servlet;
  2. import cn.hutool.extra.servlet.ServletUtil;
  3. import com.alibaba.fastjson.JSON;
  4. import org.springframework.http.MediaType;
  5. import javax.servlet.http.HttpServletResponse;
  6. /**
  7. * 客户端工具类
  8. *
  9. * @author 芋道源码
  10. */
  11. public class ServletUtils {
  12. @SuppressWarnings("deprecation") // 必须使用 APPLICATION_JSON_UTF8_VALUE,否则会乱码
  13. public static void writeJSON(HttpServletResponse response, Object object) {
  14. String content = JSON.toJSONString(object);
  15. ServletUtil.write(response, content, MediaType.APPLICATION_JSON_UTF8_VALUE);
  16. }
  17. }