英文:
how to accept a future date in a param request?
问题
我希望在我的控制器中,更新服务只接受当前日期之后的日期,我尝试使用了未来的注解,但它不起作用...你能给我一个建议吗?
特别地,如果用户输入了日期1990-04-01T12:08:56Z,我希望服务返回400,因为输入的日期不晚于当前日期,我以为`@Future`注解在这方面起作用,但我错了,它仍然允许执行服务。
@PatchMapping(path = "/{id}", produces = "application/json")
public ResponseEntity<Employee> update(@PathVariable(value = "id") Integer id,
@RequestParam(value = "afterdate") @Future @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'") Date afterdate) { ....
英文:
I would like that in my controller the update service would only accept dates after the current one, I tried to use the future annotation but it doesn't work ... could you give me a suggestion?
in particular, I would like if the user entered the date 1990-04-01T12: 08: 56Z the service would return 400 because the entered date is not later than the current one, I thought the @Future
annotation worked in this sense instead I was wrong and still allows the execution of the service
@PatchMapping(path = "/{id}", produces = "application/json")
public ResponseEntity<Employee> update(@PathVariable(value = "id") Integer id,
@RequestParam(value = "afterdate") @Future @DateTimeFormat(pattern =" yyyy-MM-dd'T'HH:mm:ss'Z'") Date afterdate) { ....
专注分享java语言的经验与见解,让所有开发者获益!
评论