JS Bin

获取Url中的参数的工具方法

/**
     * 获得url中参数
     * @param url
     * @return
     */
    public static Map<String, String> getParameter(String url) {
        Map<String, String> map = new HashMap<>();
        try {
            if (url.indexOf('?') != -1) {
                final String contents = url.substring(url.indexOf('?') + 1);
                String[] keyValues = contents.split("&");
                for (int i = 0; i < keyValues.length; i++) {
                    String key = keyValues[i].substring(0, keyValues[i].indexOf("="));
                    String value = keyValues[i].substring(keyValues[i].indexOf("=") + 1);
                    map.put(key, value);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

 

posted @ 2020-07-24 09:57  左五六  阅读(792)  评论(0编辑  收藏  举报