關(guān)于postman傳參的幾種格式 list,map 等
postman傳參的幾種格式
百度了好久,還是自己摸索出來(lái)的。。。
1.參數(shù)中有基本數(shù)據(jù)類(lèi)型還有 list集合類(lèi)型
public String addUserRole(@RequestParam("userId")Long userId,
@RequestBody List<Long> roleIdList)

2. 參數(shù)中有基本數(shù)據(jù)類(lèi)型,還有 Map<Long,List<Long>>這種類(lèi)型
addRolePermission(@RequestParam("roleId") Long roleId,
@RequestBody Map<Long, List<Long>> metaMap)

PostMan請(qǐng)求Object\List、Map類(lèi)型
Object參數(shù)傳遞
object包含一個(gè)spuId,一個(gè)skuList

List參數(shù)傳遞
一、簡(jiǎn)單的參數(shù)參數(shù)傳遞 Controller
就普通的參數(shù)傳遞即可。
/**
* 刪除Customer
* 根據(jù)ID刪除
* @return
*/
@RequestMapping("deleteCustomerById")
public Boolean deleteCustomerById(String id){
Boolean result = mongoService.deleteCustomer(id);
return result;
}
前后臺(tái)分離項(xiàng)目,使用Postman對(duì)寫(xiě)好的接口進(jìn)行測(cè)試,請(qǐng)求類(lèi)型為Post需要向后臺(tái)傳遞List<String> list數(shù)據(jù)下面是后臺(tái)控制層的java代碼
@RequestMapping(value = "/del",method = RequestMethod.POST,produces = "application/json") public Result del(@RequestBody List<String> list)
Postman頁(yè)面的請(qǐng)求可以這么寫(xiě):

二、List和數(shù)組,組成形如List<String>等基本數(shù)據(jù)類(lèi)型傳參
/**
* 批量刪除
* @param ids
* @return
*/
@RequestMapping("deleteCustomerByIds")
public Boolean deleteCustomerByIds(@RequestParam("ids[]") List<String> ids){
Boolean result = mongoService.deleteCustomer(ids);
return result;
}

三、復(fù)雜List<Object>請(qǐng)求操作
/**
* 批量刪除
* @param customers
* @return
*/
@RequestMapping("deleteCustomerByCustomers")
public Boolean deleteCustomerByCustomers(@RequestBody List<Customer> customers){
List<String> ids = new ArrayList<>();
ids.add("1234");
Boolean result = mongoService.deleteCustomer(ids);
return result;
}

實(shí)體類(lèi)中引用了一個(gè)List,泛型為其他實(shí)體類(lèi)

參數(shù)是List集合時(shí),Postman中參數(shù)格式如下圖所示:

Postman傳入多個(gè)參數(shù),請(qǐng)求異常Required request body is missing
如需要傳入一個(gè)String,一個(gè)List<String>
輸入?yún)?shù)后報(bào)錯(cuò):@RequestBody對(duì)象為空,異常Required request body is missing
直接攔截了入?yún)榭盏恼?qǐng)求,設(shè)置@RequestBody(required = false)后,將不會(huì)攔截,可以在后端進(jìn)行判斷
原因是兩個(gè)參數(shù)都使用了@RequestBody接收,正確做法應(yīng)該是分別使用@RequestParam("id"),@RequestParam("list")指定參數(shù)

Map類(lèi)型
Map<String,String>
在Body中選擇x-www-form-urlencoded的方式,將map中所需的key和value值輸入即可
Map< String, List<String> >

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java實(shí)現(xiàn)excel表格轉(zhuǎn)成json的方法
本篇文章主要介紹了Java實(shí)現(xiàn)excel表格轉(zhuǎn)成json的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09
SpringBoot?注解?@AutoConfiguration?在?2.7?版本中被新增的使用方法詳解
這篇文章主要介紹了SpringBoot?注解?@AutoConfiguration?在?2.7?版本中被新增(使用方法),本文給大家介紹的非常詳細(xì),需要的朋友可以參考下2024-09-09
AsyncHttpClient IOExceptionFilter異常過(guò)濾器
這篇文章主要為大家介紹了AsyncHttpClient IOExceptionFilter異常過(guò)濾器代碼流程解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-12-12
Java詳解數(shù)據(jù)類(lèi)型的定義與使用
Java 是一種類(lèi)型安全語(yǔ)言,編譯器存儲(chǔ)在變量中的數(shù)值具有適當(dāng)?shù)臄?shù)據(jù)類(lèi)型。學(xué)習(xí)任何一種編程語(yǔ)言都要了解其數(shù)據(jù)類(lèi)型,本文將詳細(xì)介紹 Java 中的數(shù)據(jù)類(lèi)型2022-04-04
Spring Boot @Conditional注解用法示例介紹
這篇文章主要給大家介紹了關(guān)于Spring Boot @Conditional注解用法的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Spring Boot具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
Mybatis的TypeHandler實(shí)現(xiàn)數(shù)據(jù)加解密詳解
這篇文章主要介紹了Mybatis基于TypeHandler實(shí)現(xiàn)敏感數(shù)據(jù)加密詳解,Typehandler是mybatis提供的一個(gè)接口,通過(guò)實(shí)現(xiàn)這個(gè)接口,可以實(shí)現(xiàn)jdbc類(lèi)型數(shù)據(jù)和java類(lèi)型數(shù)據(jù)的轉(zhuǎn)換,需要的朋友可以參考下2024-01-01

