簡體   English   中英

獲取 Spring 啟動 rest API 的 NumberFormatException

[英]Getting NumberFormatException for Spring Boot rest API

我正在 Spring 引導中處理以下 API:

/fetchStudents?prefix=<prefix>&fetchSize=<fetchSize>

我正在執行 rest API 如下:

  @GetMapping("/fetchStudents")
   public ResponseEntity<List<Student> getStudents(@RequestParam String prefix,
                                                   @RequestParam(defaultValue="50") int fetchSize) {
   ....
  }

在將 API 稱為: /fetchStudents?prefix='a'&fetchSize=50時,我收到NumberFormatException 我不知道如何解決這個問題。

問題可能來自被 ` 符號包圍a參數。

由於您將它發送到 URL 它應該被編碼為%60a%60

所以看起來 Spring 沒有正確讀取第一個參數,這會影響fetchSize的第二個參數

嘗試消除部分查詢參數以更好地識別問題:

  • /fetchStudents?fetchSize=50
  • /fetchStudents?fetchSize=50&prefix='a'
  • /fetchStudents?fetchSize=50&prefix=%60a%60

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM