zoukankan      html  css  js  c++  java
  • Map拼接URL地址

    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;
    
    /**
     * @Author: hoje
     * Description:
     * Date: Created in 10:05 2019/12/6 0006
     * Modified by:
     */
    public class Map2Equal {
    
        public static void main(String[] args) {
            Map<String, String> data = new HashMap<>();
            data.put("aa", "11");
            data.put("bb", "22");
            data.put("cc", "33");
            StringBuffer retStr = new StringBuffer("https://www.baidu.com");
            StringBuffer sb = new StringBuffer();
            retStr.append("?");
            if (data != null) {
                Iterator i = data.entrySet().iterator();
    
                while (i.hasNext()) {
                    Map.Entry<String, String> entry = (Map.Entry) i.next();
                    sb.append("&").append((String) entry.getKey()).append("=").append((String) entry.getValue());
                }
                String param = sb.substring(1);
                retStr.append(param);
            }
    
            System.out.println(retStr);
        }
    }

    测试结果:

    https://www.baidu.com?aa=11&bb=22&cc=33
  • 相关阅读:
    DDD 领域驱动设计
    IOC 控制反转
    WCF
    Lucene 全文检索引擎
    Redis
    Cache 缓存
    return
    PHP中empty();和isset();的区别.
    sql 简单用语
    关系型数据库
  • 原文地址:https://www.cnblogs.com/hoje/p/11993686.html
Copyright © 2011-2022 走看看