| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package com.ydtech.utils;
- import com.alibaba.fastjson.JSONObject;
- import com.ydtech.core.page.HttpResult;
- import org.springframework.web.context.request.RequestContextHolder;
- import org.springframework.web.context.request.ServletRequestAttributes;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- /**
- * HTTP工具类
- *
- * @author Louis
- * @date Jun 29, 2019
- */
- public class HttpUtils {
- /**
- * 获取HttpServletRequest对象
- *
- * @return
- */
- public static HttpServletRequest getHttpServletRequest() {
- return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
- }
- /**
- * 输出信息到浏览器
- *
- * @param response
- * @param message
- * @throws IOException
- */
- public static void write(HttpServletResponse response, Object data) throws IOException {
- response.setContentType("application/json; charset=utf-8");
- HttpResult result = HttpResult.ok(data);
- String json = JSONObject.toJSONString(result);
- response.getWriter().print(json);
- response.getWriter().flush();
- response.getWriter().close();
- }
- }
|