开发者

error while using @Valid in spring mvc 3.0

开发者 https://www.devze.com 2023-01-30 01:57 出处:网络
here what i do in a model class private Integer height; @NotBlank @Length(min = 2, max = 3) public Integer getHeight() {

here what i do in a model class

private Integer height;

@NotBlank
@Length(min = 2, max = 3)
public Integer getHeight() {
    return height;
}

public void setHeight(Integer height) {
    this.height = height;
}

but there is a validation error in the jsp page while running, it says that cannot validate the integer value.

in the 开发者_如何学JAVAmessage.properties file

NotBlank.modelClassName.height=Required in cm. Length.modelClassName.height=min {0} max (1). typeMismatch.modelClassName.height=numbers only.

help me please


Both annotations @NotBlank and @Length must be applied to an String attribute not to an Integer one, as it is stated in the links. Maybe you can use @NotNull, @Min or @Max that could be used for numbers.

0

精彩评论

暂无评论...
验证码 换一张
取 消