本篇文章給大家分享的是有關(guān)springboot怎樣讀取http請(qǐng)求url地址中的參數(shù),小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
創(chuàng)新互聯(lián)自2013年創(chuàng)立以來,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都做網(wǎng)站、成都網(wǎng)站制作網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元城子河做網(wǎng)站,已為上家服務(wù),為城子河各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:18980820575
定義一個(gè)Rest接口時(shí)通常會(huì)利用GET、POST、PUT、DELETE來實(shí)現(xiàn)數(shù)據(jù)的增刪改查;這幾種方式有的需要傳遞參數(shù),后臺(tái)開發(fā)人員必須對(duì)接收到的參數(shù)進(jìn)行參數(shù)驗(yàn)證來確保程序的健壯性
GET:一般用于查詢數(shù)據(jù),采用明文進(jìn)行傳輸,一般用來獲取一些無關(guān)用戶信息的數(shù)據(jù)
POST:一般用于插入數(shù)據(jù)
PUT:一般用于數(shù)據(jù)更新
DELETE:一般用于數(shù)據(jù)刪除;一般都是進(jìn)行邏輯刪除(即:僅僅改變記錄的狀態(tài),而并非真正的刪除數(shù)據(jù))
請(qǐng)求URL:localhost:8080/hello/id 獲取id值
實(shí)現(xiàn)代碼如下:
//java項(xiàng)目www.fhadmin.org@RestControllerpublicclass HelloController { @RequestMapping(value="/hello/{id}/{name}",method= RequestMethod.GET) public String sayHello(@PathVariable("id") Integer id,@PathVariable("name") String name){ return"id:"+id+" name:"+name; } }
在瀏覽器中 輸入地址:
localhost:8080/hello/100/hello
輸出:
id:81name:hello
獲取url參數(shù)值,默認(rèn)方式,需要方法參數(shù)名稱和url參數(shù)保持一致
請(qǐng)求URL:localhost:8080/hello?id=1000
//java項(xiàng)目www.fhadmin.org@RestControllerpublicclass HelloController { @RequestMapping(value="/hello",method= RequestMethod.GET) public String sayHello(@RequestParam Integer id){ return"id:"+id; } }
輸出:id:100
url中有多個(gè)參數(shù)時(shí),如:
localhost:8080/hello?id=98&&name=helloworld
具體代碼如下:
//java項(xiàng)目www.fhadmin.org@RestControllerpublicclass HelloController { @RequestMapping(value="/hello",method= RequestMethod.GET) public String sayHello(@RequestParam Integer id,@RequestParam String name){ return"id:"+id+ " name:"+name; } }
獲取url參數(shù)值,執(zhí)行參數(shù)名稱方式
localhost:8080/hello?userId=1000
//java項(xiàng)目www.fhadmin.org@RestControllerpublicclass HelloController { @RequestMapping(value="/hello",method= RequestMethod.GET) public String sayHello(@RequestParam("userId") Integer id){ return"id:"+id; } }
輸出:id:100
以上就是springboot怎樣讀取http請(qǐng)求url地址中的參數(shù),小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見到或用到的。希望你能通過這篇文章學(xué)到更多知識(shí)。更多詳情敬請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
分享題目:springboot怎樣讀取http請(qǐng)求url地址中的參數(shù)
文章URL:http://www.chinadenli.net/article34/jigise.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、動(dòng)態(tài)網(wǎng)站、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站收錄、服務(wù)器托管、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)