傳參是字符串集合:list<string>
當(dāng)使用getMapping()時,使用@requestParam("strs") List<String> strs
ApiPost
還有一種寫法:
?
?文章來源地址http://www.zghlxwxcb.cn/news/detail-780628.html
當(dāng)使用PostMapping()時,使用requestBody
?
?APIPost
即:
如果是List<Integer>
詳細(xì)說一下:
?
?如果使用requestParam 注意@RequestParam
里的value
一定要帶上中括號:
?
或者
?
?
?
?
?
傳參是字符串集合Map:
?
ApiPost
多種情況:
傳參在路徑上
?
?
拼接傳參?
?
?這里之所以這么復(fù)雜,是因為還上傳了文件格式,如果不需要上傳文件,直接包裝成requestBody
即如下:
@RequestBody
一般用來處理Content-Type:"application/json,application/xml"兩種格式的請求,能夠?qū)鬟^來的參數(shù)自動封裝成指定類上。
但是文件上傳Content-Type不是這個,所以兩者只能求同不能存異。
@RequestParam
通過注解@RequestParam可以輕松的將URL中的參數(shù)綁定到處理函數(shù)方法的變量中。
v1/list?page=1&pageSize=1
@PathVariable
通過 @PathVariable 可以將 URL 中占位符參數(shù)綁定到控制器處理方法的入?yún)⒅?URL 中的 {xxx} 占位符可以通過@PathVariable(“xxx”) 綁定到操作方法的入?yún)⒅小?/p>
v1/info/{roomId}
@Param
作用與dao層,把方法中的傳參映射到sql中。
@Mapper public interface UserMapper { Integer insert(@Param("username") String username, @Param("address") String address); }
對于xml文件如下:
insert into user (username,address) values (#{username},#{address});
ApiPost
參數(shù)格式:
參數(shù):數(shù)組類型 Integer[] ids
?
另一種(這兩種都沒試,我用的requestbody)
后臺接收數(shù)組
?
運行代碼:
?
文章來源:http://www.zghlxwxcb.cn/news/detail-780628.html
?
到了這里,關(guān)于ApiPost/Postman 傳參賦值詳解的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!