本篇內容介紹了“PostMan下用@RequestParam修飾數組的方法”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
PostMan傳@RequestParam修飾的數組
那么用PostMan該如何傳入數組呢?
param參數數組使用注意點
1、只能為一位數組使用 params 關鍵字
2、不能只依賴 params 關鍵字來重載一個方法
3、不允許為 params
4、params 數組
5、非params方法優先
6、有歧義的重載編譯不能通過
筆者今天被一個問題困擾了一段時間
看如下代碼:
@RestController
@RequestMapping("/getTest")
public class GetTestController {
@RequestMapping("/listRaramTest")
public List<String> listRaramTest(@RequestParam("userIdList") List<String> userIdList){
return userIdList;
}
}@RequestParam修飾了一個list
實際上很簡單
在這里記錄一下:

其實只要按參數名字傳入一個按都好分隔的字符串就好了
不能為多為數組使用,否則編譯不能通過。
params 關鍵字不構成方法簽名的一部分,例如:
//編譯時錯誤:重復的聲明 public static int Max(int[] paramList) ... public static int Max(params int[] paramList) ...
數組指定 ref 或 out修飾符。
必須是方法的最后一個參數,沒個方法中也只能有一個 params 數組參數。
//編譯時錯誤 public static int Max(params int[] paramList,int i) ...
public static int Max(int first,int second) //優先 ... public static int Max(params int[] paramList) ...
對于上面的重載方法,傳入兩個 int 參數時,調用上面的方法,傳入其它任意數量的 int 參數時,調用下面的方法。這樣做并非多余,實則起到優化作用。
//編譯時錯誤 public static int Max(params int[] paramList) ... public static int Max(int i, params int[] paramList) ...
“PostMan下用@RequestParam修飾數組的方法”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。