關(guān)于postman傳參的幾種格式 list,map 等
postman傳參的幾種格式
百度了好久,還是自己摸索出來的。。。
1.參數(shù)中有基本數(shù)據(jù)類型還有 list集合類型
public String addUserRole(@RequestParam("userId")Long userId, @RequestBody List<Long> roleIdList)
2. 參數(shù)中有基本數(shù)據(jù)類型,還有 Map<Long,List<Long>>這種類型
addRolePermission(@RequestParam("roleId") Long roleId, @RequestBody Map<Long, List<Long>> metaMap)
PostMan請求Object\List、Map類型
Object參數(shù)傳遞
object包含一個spuId,一個skuList
List參數(shù)傳遞
一、簡單的參數(shù)參數(shù)傳遞 Controller
就普通的參數(shù)傳遞即可。
/** * 刪除Customer * 根據(jù)ID刪除 * @return */ @RequestMapping("deleteCustomerById") public Boolean deleteCustomerById(String id){ Boolean result = mongoService.deleteCustomer(id); return result; }
前后臺分離項目,使用Postman對寫好的接口進(jìn)行測試,請求類型為Post需要向后臺傳遞List<String> list數(shù)據(jù)下面是后臺控制層的java代碼
@RequestMapping(value = "/del",method = RequestMethod.POST,produces = "application/json") public Result del(@RequestBody List<String> list)
Postman頁面的請求可以這么寫:
二、List和數(shù)組,組成形如List<String>等基本數(shù)據(jù)類型傳參
/** * 批量刪除 * @param ids * @return */ @RequestMapping("deleteCustomerByIds") public Boolean deleteCustomerByIds(@RequestParam("ids[]") List<String> ids){ Boolean result = mongoService.deleteCustomer(ids); return result; }
三、復(fù)雜List<Object>請求操作
/** * 批量刪除 * @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; }
實體類中引用了一個List,泛型為其他實體類
參數(shù)是List集合時,Postman中參數(shù)格式如下圖所示:
Postman傳入多個參數(shù),請求異常Required request body is missing
如需要傳入一個String,一個List<String>
輸入?yún)?shù)后報錯:@RequestBody對象為空,異常Required request body is missing
直接攔截了入?yún)榭盏恼埱螅O(shè)置@RequestBody(required = false)后,將不會攔截,可以在后端進(jìn)行判斷
原因是兩個參數(shù)都使用了@RequestBody接收,正確做法應(yīng)該是分別使用@RequestParam("id"),@RequestParam("list")指定參數(shù)
Map類型
Map<String,String>
在Body中選擇x-www-form-urlencoded的方式,將map中所需的key和value值輸入即可
Map< String, List<String> >
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java實現(xiàn)excel表格轉(zhuǎn)成json的方法
本篇文章主要介紹了Java實現(xiàn)excel表格轉(zhuǎn)成json的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-09-09SpringBoot?注解?@AutoConfiguration?在?2.7?版本中被新增的使用方法詳解
這篇文章主要介紹了SpringBoot?注解?@AutoConfiguration?在?2.7?版本中被新增(使用方法),本文給大家介紹的非常詳細(xì),需要的朋友可以參考下2024-09-09AsyncHttpClient IOExceptionFilter異常過濾器
這篇文章主要為大家介紹了AsyncHttpClient IOExceptionFilter異常過濾器代碼流程解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-12-12Spring Boot @Conditional注解用法示例介紹
這篇文章主要給大家介紹了關(guān)于Spring Boot @Conditional注解用法的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Spring Boot具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11Mybatis的TypeHandler實現(xiàn)數(shù)據(jù)加解密詳解
這篇文章主要介紹了Mybatis基于TypeHandler實現(xiàn)敏感數(shù)據(jù)加密詳解,Typehandler是mybatis提供的一個接口,通過實現(xiàn)這個接口,可以實現(xiàn)jdbc類型數(shù)據(jù)和java類型數(shù)據(jù)的轉(zhuǎn)換,需要的朋友可以參考下2024-01-01