gpt4 book ai didi

java - 获取 Spring Boot REST API 的 NumberFormatException

转载 作者:行者123 更新时间:2023-12-01 16:26:05 25 4
gpt4 key购买 nike

我正在 Spring Boot 中开发以下 API:

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

我正在实现其余 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

关于java - 获取 Spring Boot REST API 的 NumberFormatException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62145344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com