我有一个领域需要double
。如果您输入String
,默认消息类似于:
Failed to convert property value of type java.lang.String to required type java.lang.Double for property price; nested exception is java.lang.NumberFormatException: For input string: "fsd"
未输入值时的自定义消息。我已将此消息设置为执行以下操作:
@NotNull(message = "price is required")
private Double price;
是否有针对类型不匹配的等效注释?
没有针对类型不匹配的验证注释,因为这种情况发生在数据绑定期间,并且如果字段的数据绑定失败,则不会进行验证。但是,如果您想更改错误列表中显示的消息,您应该可以使用messages.properties
文件位于项目的资源包中。我在消息文件中使用以下键,该键适用于 joda-time 日期字段:
typeMismatch.org.joda.time.LocalDate=Dates must be entered in the format MM/DD/YYYY
See 这个问题了解更多信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)