ResolverStyle.STRICT在`@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)中不起作用 [英] ResolverStyle.STRICT is not working in `@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)`

查看:2524
本文介绍了ResolverStyle.STRICT在`@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用:

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
@JsonFormat( pattern = "MM-dd-yyyy" )
private LocalDate start;

但接受 02-30-2019 并自动转换为 02-28-2019 。但是我希望限制那个日期。

but it accept 02-30-2019 and convert to 02-28-2019 Automatically. But i want restrict that date.

我也用过:

@DateTimeFormat(iso = java.time.format.DateTimeFormatter.ISO_DATE)
@JsonFormat( pattern = "MM-dd-yyyy" )
private LocalDate start;

但它会产生编译时错误:属性值必须是常量

but it give compile time error: Attribute value must be constant.

ankit here:

ankit here:

我有同样的问题,也用过 u 代替 y 但不是帮助:

I have same issue and also used u in place of y but not help:

@FutureOrPresent
@DateTimeFormat( iso = DateTimeFormat.ISO.DATE,pattern = "MM-dd-uuuu")
@JsonFormat( pattern = "MM-dd-uuuu" )
private LocalDate start;

我想在解析时限制。它接受 02-31-2019 并自动转换为 02-28-2019 。参考: https://stackoverflow.com/a/41104034/6097074

i want to restrict at time of parsing. It accept 02-31-2019 and convert automatically to 02-28-2019. refer: https://stackoverflow.com/a/41104034/6097074

现在 09/08/2018

如果我正在使用:
private LocalDate start; //不使用DateTimeFormat和JsonFormat注释

If i am using: private LocalDate start;//without using DateTimeFormat and JsonFormat annotation

这项工作正常,如果我使用: yyyy-MM-dd json中的格式日期即 2014年1月1日
但是我需要解析 MM-dd-yyyy

this work fine if i use: yyyy-MM-dd format date in json i.e. 2014-01-01. But i need to parse to MM-dd-yyyy.

有助于解决这个问题,
谢谢。

Kind help to solve this, Thanks.

推荐答案

我找到了解决问题的方法:

I got solution for your problem:

删除以下行

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
@JsonFormat( pattern = "MM-dd-yyyy" )

并且只需使用:

private LocalDate start;

并以 yyyy-MM-dd yyyy发送日期-MM-ddTHH:mm:ss (使用ResolverStyle.Strict在Spring中解析日期的默认日期格式)日期格式。

and send date in yyyy-MM-dd or yyyy-MM-ddTHH:mm:ss (default date format for Date parsing in spring with ResolverStyle.Strict) date format.

这篇关于ResolverStyle.STRICT在`@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆