| | |
| | | import org.springframework.web.context.request.RequestAttributes;
|
| | | import org.springframework.web.context.request.RequestContextHolder;
|
| | | import org.springframework.web.context.request.ServletRequestAttributes;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.alibaba.fastjson2.JSON;
|
| | | import com.ruoyi.common.core.constant.Constants;
|
| | | import com.ruoyi.common.core.domain.R;
|
| | | import com.ruoyi.common.core.text.Convert;
|
| | |
| | | *
|
| | | * @param response 渲染对象
|
| | | * @param string 待渲染的字符串
|
| | | * @return null
|
| | | */
|
| | | public static String renderString(HttpServletResponse response, String string)
|
| | | public static void renderString(HttpServletResponse response, String string)
|
| | | {
|
| | | try
|
| | | {
|
| | |
| | | {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | public static boolean isAjaxRequest(HttpServletRequest request)
|
| | | {
|
| | | String accept = request.getHeader("accept");
|
| | | if (accept != null && accept.indexOf("application/json") != -1)
|
| | | if (accept != null && accept.contains("application/json"))
|
| | | {
|
| | | return true;
|
| | | }
|
| | |
|
| | | String xRequestedWith = request.getHeader("X-Requested-With");
|
| | | if (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1)
|
| | | if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest"))
|
| | | {
|
| | | return true;
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | String ajax = request.getParameter("__ajax");
|
| | | if (StringUtils.inStringIgnoreCase(ajax, "json", "xml"))
|
| | | {
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | return StringUtils.inStringIgnoreCase(ajax, "json", "xml");
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | response.setStatusCode(status);
|
| | | response.getHeaders().add(HttpHeaders.CONTENT_TYPE, contentType);
|
| | | R<?> result = R.fail(code, value.toString());
|
| | | DataBuffer dataBuffer = response.bufferFactory().wrap(JSONObject.toJSONString(result).getBytes());
|
| | | DataBuffer dataBuffer = response.bufferFactory().wrap(JSON.toJSONString(result).getBytes());
|
| | | return response.writeWith(Mono.just(dataBuffer));
|
| | | }
|
| | | }
|