
com.taotao.cloud.openfeign.utils.QueryUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of taotao-cloud-starter-openfeign Show documentation
Show all versions of taotao-cloud-starter-openfeign Show documentation
taotao-cloud-starter-openfeign
/*
* Copyright (c) 2020-2030, Shuigedeng ([email protected] & https://blog.taotaocloud.top/).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.taotao.cloud.openfeign.utils;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
/**
* 解析request的query参数工具
*
* @author shuigedeng
* @version 2023.07
* @since 2023-07-06 09:34:19
*/
public class QueryUtils {
/**
* 通过query字符串得到参数的map
*
* @param queryString ?后的字符
* @return {@link Map }<{@link String }, {@link String }>
* @since 2023-07-06 09:34:19
*/
public static Map getQueryMap(String queryString) {
if (StringUtils.isNotBlank(queryString)) {
return Arrays.stream(queryString.split("&"))
.map(item -> item.split("="))
.collect(Collectors.toMap(
key -> key[0],
value -> value.length > 1 && StringUtils.isNotBlank(value[1]) ? value[1] : ""));
}
return Collections.emptyMap();
}
/**
* 通过url获取参数map
*
* @param uri uri
* @return {@link Map }<{@link String }, {@link String }>
* @since 2023-07-06 09:34:24
*/
public static Map getQueryMap(URI uri) {
if (Objects.nonNull(uri)) {
return getQueryMap(uri.getQuery());
}
return Collections.emptyMap();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy