有图有真相的QQ资源、网赚教程分享,高质量的网络教程和软件下载
保存到桌面加入收藏设为首页
冷牛教程网
当前位置:首页 > 技术文章 > JAVA

Springboot获取Controller层传的参数

2021-07-21 11:15:17   admin      901  
 /**
     * 1.直接把表单的参数写在Controller相应的方法的形参中
      * @param username
     * @param password
     * @return
     */
    @RequestMapping("/addUser1")
    public String addUser1(String username,String password) {
        System.out.println("username is:"+username);
        System.out.println("password is:"+password);
        return "demo/index";

}


    /**      * 2、通过HttpServletRequest接收       * @param request      * @return      */     @RequestMapping("/addUser2")     public String addUser2(HttpServletRequest request) {         String username=request.getParameter("username");         String password=request.getParameter("password");         System.out.println("username is:"+username);         System.out.println("password is:"+password);         return "demo/index";     }



@RequestMapping(value="/addUser4/{username}/{password}",method=RequestMethod.GET)
public String addUser4(@PathVariable String username,@PathVariable String password) {
        System.out.println("username is:"+username);
        System.out.println("password is:"+password);
        return "demo/index";
    }
    @RequestMapping(value="/addUser6",method=RequestMethod.GET)
    public String addUser6(@RequestParam("username") String username,@RequestParam("password") String password) {
        System.out.println("username is:"+username);
        System.out.println("password is:"+password);
        return "demo/index";
    }







相关评论
冷牛网络 2015-2021 版权所有  豫ICP备2021000561号-1