springMVC第一天

 来看几个例子 , 秒懂 , 很简单

//http://localhost/param5?username=zhangsan&age=18
    @GetMapping("/param5")
    public String param5(@RequestParam Map<String,String> map){
        map.forEach((k,v)->{
            System.out.println(k+"==>"+v);
        });
        return "/index.jsp";
    }


    //http://localhost/param4?hobby=zq&hobby=pq&hobby=tq
    @GetMapping("/param4")
    public String param4(@RequestParam List<String> hobby){
        for (String s : hobby) {
            System.out.println(s);
        }
        return "/index.jsp";
    }


    //http://localhost/param3?hobby=zq&hobby=pq&hobby=tq
    @GetMapping("/param3")
    public String param3(String[] hobby){
        for (String s : hobby) {
            System.out.println(s);
        }
        return "/index.jsp";
    }


    //http://localhost/param2?username=zhangsan&age=18
    @GetMapping("/param2")
    public String param2(@RequestParam(value="username",required = false,defaultValue = "haohao") String name, Integer age){
        System.out.println(name+"===="+age);
        return "/index.jsp";
    }

    //http://localhost/param1?username=zhangsan&age=18
    @RequestMapping("/param1")
    public String param1(String username,int age){
        System.out.println(username+"===="+age);
        return "/index.jsp";
    }

来看第二种方式

 

 用一个user类封装信息 , 很方便 ,(SpringMVC容器已经帮我们把User对象创建了)

    //http://localhost/param6?username=zhangsan&age=18&hobbies=zq&hobbies=pq&birthday=2018/11/11&address.city=tj&address.area=bh
    @GetMapping("/param6")
    public String param6(User user){
        System.out.println(user);
        return "/index.jsp";
    }

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-21 12:40:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-21 12:40:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-02-21 12:40:01       87 阅读
  4. Python语言-面向对象

    2024-02-21 12:40:01       96 阅读

热门阅读

  1. C/C++区别、优劣详解!!!!!

    2024-02-21 12:40:01       44 阅读
  2. Huggingface镜像网站下载语言模型方法

    2024-02-21 12:40:01       56 阅读
  3. WSL系统手动挂在移动硬盘

    2024-02-21 12:40:01       51 阅读
  4. Spring中的bean的作用域为什么默认为单例的?

    2024-02-21 12:40:01       45 阅读
  5. 版本比较工具类VersionUtil

    2024-02-21 12:40:01       47 阅读
  6. SVN服务备份

    2024-02-21 12:40:01       44 阅读
  7. python之ftp小工具

    2024-02-21 12:40:01       42 阅读
  8. kotlin协程学习总结

    2024-02-21 12:40:01       59 阅读
  9. 3DTile是不是没有坐标的选择?

    2024-02-21 12:40:01       51 阅读
  10. flask get请求

    2024-02-21 12:40:01       52 阅读
  11. 511. 游戏玩法分析 I

    2024-02-21 12:40:01       55 阅读
  12. 实现一个Windows环境一键启停Oracle的bat脚本

    2024-02-21 12:40:01       48 阅读
  13. WPS AI功能测试

    2024-02-21 12:40:01       58 阅读