如何将弦转换为日期在百里香中?

发布于 2025-02-08 00:55:07 字数 480 浏览 1 评论 0原文

我有以下输入:

<input name="dateOfOrder" class="form-control" id="dateOfOrder" type="date" th:field="*{{dateOfOrder}}" />

哦,这是将其插入的DTO的片段:

@DateTimeFormat(pattern="yyyy-MM-dd")
private LocalDate dateOfOrder;

不幸的是,我有一个例外:

无法从类型[java.lang.string]转换为类型 [java.time.localdate]从价值'2022-06-14';嵌套异常是 java.lang.illegalargumentException:解析尝试失败 [2022-06-14]。

我不熟练掌握百里香,想暗示这里有什么问题

I have the following input:

<input name="dateOfOrder" class="form-control" id="dateOfOrder" type="date" th:field="*{{dateOfOrder}}" />

And oh this is the fragment of the DTO into which they are inserted :

@DateTimeFormat(pattern="yyyy-MM-dd")
private LocalDate dateOfOrder;

Unfortunately I get an exception:

Failed to convert from type [java.lang.String] to type
[java.time.LocalDate] from value '2022-06-14'; nested exception is
java.lang.IllegalArgumentException: Parse attempt failed from value
[2022-06-14].

I`m not proficient in Thymeleaf and would like some hints on what is wrong here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

固执像三岁 2025-02-15 00:55:07

您需要使用胸腺格式。

<input name="dateOfOrder" class="form-control" id="dateOfOrder" type="date" th:field="${#dates.format(dateOfOrder, 'yyyy-MM-dd')}" />

You need to use Thymeleaf formatting.

<input name="dateOfOrder" class="form-control" id="dateOfOrder" type="date" th:field="${#dates.format(dateOfOrder, 'yyyy-MM-dd')}" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文