後端用 @requestparam 或者servlet 獲取引數。
後端用 @rquestbody 獲取引數,或者@requestparam獲取。
@pathvariable:
一般我們使用uri template樣式對映時用,即url/這種形式,也就是一般我們使用的get,delete,put方法會使用到的,我們可以獲取url後所跟的引數。
@requestparam:
@requestbody:
@requestheader
獲取頭資訊裡的值
@cookievalue
獲取cookie值
引數來自路徑
1.get請求,url路徑傳參
http://localhost:4001/api/unit?code=111
後端要獲取code引數,可以使用@requestparam註解
2.get請求,url路徑引數@restcontroller
public class hellocontroller
}
http://localhost:4001/api/unit/1
後端使用@pathvariable可以接收路徑引數1。
一般引數來自路徑的,為get請求時,使用@pathvariable或者@requestparam獲取引數值,獲取路徑引數。@restcontroller
public class hellocontroller
}
@pathvariable一般用於獲取獲取url/
@requestparam獲取查詢引數。即url?name=xx
引數來自請求體body
一般是post請求,後端接受方式為用map接收,或者實體物件接收
//map接收
public void demo1(@requestbody mapperson)
//或者是實體物件接收
public void demo1(@requestbody person person)
//或者直接集合的方式,這樣前端傳的是列表
@responsebody
public listgetjsonval(@requestbody listperson) throws ioexception
return user;
}
SpringBoot獲取properties配置
前言 在專案中,很多時候需要把配置寫在properties裡,部署的時候也需要切換不同的環境來選擇正確的配置的引數,也有時候需要將mq redis等第三方配置新建乙個properties檔案在專案中引用。1.因為是spring的環境,當然首先需要搭建好spring環境。package com.exa...
SpringBoot獲取properties配置
擼了今年阿里 網易和美團的面試,我有乙個重要發現.前言 在專案中,很多時候需要把配置寫在properties裡,部署的時候也需要切換不同的環境來選擇正確的配置的引數,也有時候需要將mq redis等第三方配置新建乙個properties檔案在專案中引用。1.因為是spring的環境,當然首先需要搭建...
SpringBoot獲取資料
配置檔案中資料 name abc 物件persion name lele age 29 物件行內寫法 persion2 陣列address beijing shanghai 陣列行內寫法 address2 beijing,shanghai msg1 hello n world 不會識別轉譯字元,原樣...