java url参数转map,urlUtil参数转map

package com.chinanetcenter.broadband.util;

import org.apache.commons.lang.StringUtils;

import java.util.HashMap;

import java.util.Map;

/**

* Created by yugj on 2015/8/24.

*/

public class URLUtil {

/**

* 格式化get类型参数

* orderCode="2015xx"&status="PAID" 转map

* @param urlParam

* @return

*/

public static Map formatParam(String urlParam) {

Map mapRequest = new HashMap();

String[] arrSplit = null;

if (StringUtils.isBlank(urlParam)) {

return mapRequest;

}

//每个键值为一组

arrSplit = urlParam.split("[&]");

for (String strSplit : arrSplit) {

String[] arrSplitEqual = null;

arrSplitEqual = strSplit.split("[=]");

//解析出键值

if (arrSplitEqual.length > 1) {

//正确解析

mapRequest.put(arrSplitEqual[0], arrSplitEqual[1]);

} else {

if (arrSplitEqual[0] != "") {

//只有参数没有值,不加入

mapRequest.put(arrSplitEqual[0], "");

}

}

}

return mapRequest;

}

}

你可能感兴趣的:(java,url参数转map)