【发布时间】:2016-05-26 21:40:32
【问题描述】:
我有一个 spring-boot 应用程序,它具有以下端点:
@RequestMapping("/my-end-point")
public MyCustomObject handleProduct(
@RequestParam(name = "productId") String productId,
@RequestParam(name = "maxVersions", defaultValue = "1") int maxVersions,
){
// my code
}
这应该处理表单的请求
/my-end-point?productId=xyz123&maxVersions=4
但是,当我指定 maxVersions=3.5 时,这会抛出 NumberFormatException(原因很明显)。如何优雅地处理这个NumberFormatException 并返回错误消息?
【问题讨论】:
标签: java spring exception-handling spring-boot http-request-parameters