我决定使用 JSR303 来验证我在 Spring 3.0 MVC 应用程序中的表单。当我尝试检查 Integer
变量上的 @NotEmpty
时出现异常:
javax.validation.UnexpectedTypeException: No validator could be found for type: java.lang.Integer
首先这个变量被声明为 int
(protected int partCount
) 但我在 Spring 论坛上发现原语可能会导致一些问题,所以我将其更改为整数。还是一样的异常(exception)。有什么想法吗?
附言。 Double
和 Timestamp
情况相同,字符串没有问题
谢谢
最佳答案
不确定您使用的是什么实现,但这是 Hibernate Validator 写的关于 NotEmpty
的内容注解(不是 Bean 验证规范的一部分):
Check that a String is not empty (not null and length > 0) or that a Collection (or array) is not empty (not null and length > 0)
关于java - 使用 JSR303 验证整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3761654/