| | |
| | | package com.ruoyi.common.core.utils;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.io.UnsupportedEncodingException;
|
| | | import java.net.URLDecoder;
|
| | | import java.net.URLEncoder;
|
| | | import java.util.Enumeration;
|
| | | import java.util.LinkedHashMap;
|
| | | import java.util.Map;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | | import javax.servlet.http.HttpSession;
|
| | | import org.springframework.core.io.buffer.DataBuffer;
|
| | | import org.springframework.http.HttpHeaders;
|
| | | import org.springframework.http.HttpStatus;
|
| | | import org.springframework.http.MediaType;
|
| | | import org.springframework.http.server.reactive.ServerHttpResponse;
|
| | | 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.ruoyi.common.core.constant.Constants;
|
| | | import com.ruoyi.common.core.domain.R;
|
| | | import com.ruoyi.common.core.text.Convert;
|
| | | import reactor.core.publisher.Mono;
|
| | |
|
| | | /**
|
| | | * 客户端工具类
|
| | |
| | | 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);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 内容编码
|
| | | * |
| | | * @param str 内容
|
| | | * @return 编码后的内容
|
| | | */
|
| | | public static String urlEncode(String str)
|
| | | {
|
| | | try
|
| | | {
|
| | | return URLEncoder.encode(str, Constants.UTF8);
|
| | | }
|
| | | catch (UnsupportedEncodingException e)
|
| | | {
|
| | | return "";
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 内容解码
|
| | | * |
| | | * @param str 内容
|
| | | * @return 解码后的内容
|
| | | */
|
| | | public static String urlDecode(String str)
|
| | | {
|
| | | try
|
| | | {
|
| | | return URLDecoder.decode(str, Constants.UTF8);
|
| | | }
|
| | | catch (UnsupportedEncodingException e)
|
| | | {
|
| | | return "";
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 设置webflux模型响应
|
| | | *
|
| | | * @param response ServerHttpResponse
|
| | | * @param value 响应内容
|
| | | * @return Mono<Void>
|
| | | */
|
| | | public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value)
|
| | | {
|
| | | return webFluxResponseWriter(response, HttpStatus.OK, value, R.FAIL);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 设置webflux模型响应
|
| | | *
|
| | | * @param response ServerHttpResponse
|
| | | * @param code 响应状态码
|
| | | * @param value 响应内容
|
| | | * @return Mono<Void>
|
| | | */
|
| | | public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value, int code)
|
| | | {
|
| | | return webFluxResponseWriter(response, HttpStatus.OK, value, code);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 设置webflux模型响应
|
| | | *
|
| | | * @param response ServerHttpResponse
|
| | | * @param status http状态码
|
| | | * @param code 响应状态码
|
| | | * @param value 响应内容
|
| | | * @return Mono<Void>
|
| | | */
|
| | | public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, HttpStatus status, Object value, int code)
|
| | | {
|
| | | return webFluxResponseWriter(response, MediaType.APPLICATION_JSON_VALUE, status, value, code);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 设置webflux模型响应
|
| | | *
|
| | | * @param response ServerHttpResponse
|
| | | * @param contentType content-type
|
| | | * @param status http状态码
|
| | | * @param code 响应状态码
|
| | | * @param value 响应内容
|
| | | * @return Mono<Void>
|
| | | */
|
| | | public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, String contentType, HttpStatus status, Object value, int code)
|
| | | {
|
| | | 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());
|
| | | return response.writeWith(Mono.just(dataBuffer));
|
| | | }
|
| | | }
|