| | |
| | | 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;
|
| | |
| | | public static Integer getParameterToInt(String name, Integer defaultValue)
|
| | | {
|
| | | return Convert.toInt(getRequest().getParameter(name), defaultValue);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取Boolean参数
|
| | | */
|
| | | public static Boolean getParameterToBool(String name)
|
| | | {
|
| | | return Convert.toBool(getRequest().getParameter(name));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取Boolean参数
|
| | | */
|
| | | public static Boolean getParameterToBool(String name, Boolean defaultValue)
|
| | | {
|
| | | return Convert.toBool(getRequest().getParameter(name), defaultValue);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public static String getHeader(HttpServletRequest request, String name)
|
| | | {
|
| | | String value = request.getHeader(name);
|
| | | if (StringUtils.isEmpty(value))
|
| | | {
|
| | | return StringUtils.EMPTY;
|
| | | }
|
| | | return urlDecode(value);
|
| | | }
|
| | |
|
| | | public static Map<String, String> getHeaders(HttpServletRequest request)
|
| | | {
|
| | | Map<String, String> map = new LinkedHashMap<>();
|
| | | Map<String, String> map = new LinkedCaseInsensitiveMap<>();
|
| | | Enumeration<String> enumeration = request.getHeaderNames();
|
| | | if (enumeration != null)
|
| | | {
|
| | |
| | | *
|
| | | * @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");
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | }
|
| | | catch (UnsupportedEncodingException e)
|
| | | {
|
| | | return "";
|
| | | return StringUtils.EMPTY;
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | }
|
| | | catch (UnsupportedEncodingException e)
|
| | | {
|
| | | return "";
|
| | | return StringUtils.EMPTY;
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | 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));
|
| | | }
|
| | | }
|