【发布时间】:2020-07-19 23:06:49
【问题描述】:
我在控制器获取请求中定义了一个路径变量:
@PathVariable("ticketId") final Long ticketId
如何检查这个值不为空?
使用读取https://www.baeldung.com/spring-validate-requestparam-pathvariable@NotBlank,但未提及检查null。
使用:
if ticketId == Null {
//return message indicating to user that null has been passed to path
}
似乎是一种不好的做法,应该改用try/catch 吗?
【问题讨论】:
-
您可以使用@NotNull 进行空检查
-
If(StringUtils.isNotEmpty(ticketId)) 应该足够了
标签: java spring spring-boot rest model-view-controller