如何在参数请求中接受未来日期?

huangapple 未分类评论50阅读模式
英文:

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 = &quot;/{id}&quot;, produces = &quot;application/json&quot;)
	public ResponseEntity&lt;Employee&gt; update(@PathVariable(value = &quot;id&quot;) Integer id,
			@RequestParam(value = &quot;afterdate&quot;) @Future @DateTimeFormat(pattern =&quot; yyyy-MM-dd&#39;T&#39;HH:mm:ss&#39;Z&#39;&quot;)  Date afterdate) { .... 

huangapple
  • 本文由 发表于 2020年3月16日 02:05:07
  • 转载请务必保留本文链接:https://java.coder-hub.com/60696046.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定