gpt4 book ai didi

spring - 在 Spring 验证期间包装 PropertyEditor 异常

转载 作者:行者123 更新时间:2023-12-04 06:40:04 24 4
gpt4 key购买 nike

当我提交 Spring 表单并且 PropertyEditor 无法转换值时,会引发异常,并且这样的消息最终会出现在我的验证器错误对象中:

Failed to convert property value of type java.lang.String to required type
org.joda.time.DateMidnight for property startDate; nested exception is
java.lang.IllegalArgumentException: Invalid format: "2010-111" is malformed at "1"

我可以以某种方式包装它,提供更友好的消息以显示在屏幕上吗?

我在我的 Controller 中使用 @Valid ,在我的表单中使用以下内容:
@NotNull
protected DateMidnight startDate;

谢谢

最佳答案

此错误消息包含消息代码,例如 typeMismatch.objectName.startDate (见 DefaultMessageCodesResolver)。要显示用户友好的消息,您需要 declare a MessageSource 与相应的消息。

关于spring - 在 Spring 验证期间包装 PropertyEditor 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4366026/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com