![](/img/trans.png)
[英]How to avoid NumberFormatException in Spring boot API
[英]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.