【问题标题】:Format message in invalid Hibernate data validation在无效的 Hibernate 数据验证中格式化消息
【发布时间】:2013-08-16 11:24:56
【问题描述】:

我想知道我是否可以在 Hibernate Validator 中使用关于日期格式错误的个人错误消息进行格式化。

我的类属性看起来像这样。

@DateTimeFormat(pattern = "hh:mm")
private Date hourOpen;

表单中的默认错误和消息:错误弹簧标签。

Failed to convert property value of type java.lang.String to required type java.util.Date for property hourOpen; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @org.springframework.format.annotation.DateTimeFormat java.util.Date for value 11; nested exception is java.lang.IllegalArgumentException: Unable to parse 11

我想在 form:error spring 标记中显示“日期格式错误”消息。

提前谢谢你。

【问题讨论】:

    标签: hibernate message validation


    【解决方案1】:

    获取默认消息的关键是:{typeMismatch.yourResultObject.objectAttribute}。

    【讨论】:

    • 您能详细说明一下吗?你把这把钥匙放在哪里了?
    • 在 lang-xx.properties 中。
    • @Paul 在 messages.properties 文件中添加 typeMismatch.student.dateOfBirth = 出生日期:非法日期格式!
    猜你喜欢
    • 1970-01-01
    • 2016-10-09
    • 2012-12-25
    • 1970-01-01
    • 2012-01-20
    • 1970-01-01
    • 2015-11-19
    • 1970-01-01
    • 2016-05-24
    相关资源
    最近更新 更多