zoukankan      html  css  js  c++  java
  • mvc不知道参数名,获取所有参数和值

      // Java在不知道参数名称的情况下 获取参数值(方式一)
            Enumeration<String> e = request.getParameterNames();
            while (e.hasMoreElements()) {
                String name = e.nextElement();
                String value = request.getParameter(name);
                //System.out.println(name + "=" + value);
            }
      // Java在不知道参数名称的情况下 获取参数值(方式二)
            Map<String, String[]> map = request.getParameterMap();
            Set<Map.Entry<String, String[]>> itermap = map.entrySet();
            for (Map.Entry<String, String[]> entry : itermap) {
                String key = entry.getKey();
                String value[] = entry.getValue();
                //System.out.println(key + ":" + value[0]);
            }

    测试

    @RequestMapping("/{url}")
        public  Map<String,String> test22(HttpServletRequest request,@PathVariable String url){
            System.out.println(url);
            Map<String,String> map= new HashMap<String,String>();
            map.put("url",url);
            Enumeration<String> e = request.getParameterNames();
            while (e.hasMoreElements()) {
                String name = e.nextElement();
                String value = request.getParameter(name);
                map.put(name,value);
            }
    
    
            return map;
        }
  • 相关阅读:
    Bufferedreader和BufferedWriter(带缓存的输入输出)
    FileReader和FileWriter
    Map接口的类实现
    Map接口
    Set集合
    List接口的实现类
    获取文本框或密码框中的内容
    ADTS (zz)
    初级美语 L003:My Family 解析
    初级美语 L001:Self Introduction 解析
  • 原文地址:https://www.cnblogs.com/javakangkang/p/14326364.html
Copyright © 2011-2022 走看看