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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM