springboot后端controller参数接收

参考:https://blog.csdn.net/a532672728/article/details/78057218

get方法 :

1. http://localhost:8080/0919/test1?name=xxx&pwd=yyy

方法一:String test String name,string pwd)   名字匹配直接注入

方法二:String  test(User user)  //user对象的属性名匹配上,自动注入

方法三:String test (HttpServletRequest  request)

               {

                  String name=request.getParameter("name");

     String pwd=request.getParameter("pwd");              

    }

方法四:RequestParam    其实和方法一一样,自动匹配不上,手动匹配   

     String test(@RequestParam(“name”) aaa,@RequestParam(“pwd”),bbb)

2.  http://localhost:8080/0919/test/xxx/yyy

方法1:  PathVariable:  这个和上面都不一样,上面是用查询字符串,这个是用路由。 此方法和上面四种可以混用。

             路由上写好  @RequestMapping={value= /test/sss/{a}/{b}}

             String test (@PathVariable a String Name,@PathVariable b String Pwd)

    {

     

    }

 post方法:  参考这里:https://blog.csdn.net/suki_rong/article/details/80445880

原文地址:https://www.cnblogs.com/lhuser/p/11145041.html