2016-05-25 34 views
0

登録フォームに入力されたデータを検証しようとしています。タイプのバリデータが見つかりませんでした:java.lang.String

エラーメッセージ: org.springframework.web.util.NestedServletException:要求の処理に失敗しました。ネストされた例外はjavax.validation.UnexpectedTypeExceptionです:HV000030:java.lang.String型のバリデータが見つかりませんでした。

モデルクラス:

@Configuration 
public class Student { 

    private int studentId; 

    @NotNull(message = "First name should not be empty") 
    @Size(min=03, max=20, message = "Minimum 3 to Maximum 20 characters are allowed") 
    @Pattern(regexp="/^[a-zA-Z]*$/") 
    private String firstName; 

    @NotNull(message = "Last name should not be empty") 
    @Size(min=03, max=20, message = "Minimum 3 to Maximum 20 characters are allowed") 
    @Pattern(regexp="/^[a-zA-Z]*$/") 
    private String lastName; 

    @NotNull(message = "Display name should not be empty") 
    @Pattern(regexp="^[A-Za-z0-9]*$", message = "Please enter a valid display name") 
    @Size(min=05, max=15, message="Minimum 3 to Maximum 15 characters are allowed") 
    private String displayName; 

    @NotNull(message = "Date of birth should not be empty") 
    @DateTimeFormat(pattern="yyyy/MM/dd/") 
    @Past (message="Only the past date is valid") 
    private String dateOfBirth; 

    @NotNull(message = "Email should not be empty") 
    @Email 
    private String email; 

    @NotNull(message = "Password should not be empty") 
    @Pattern.List({ 
     @Pattern(regexp = "(?=.*[0-9])", message = "Password must contain one digit."), 
     @Pattern(regexp = "(?=.*[a-z])", message = "Password must contain one lowercase letter."), 
     @Pattern(regexp = "(?=.*[a-z])", message = "Password must contain one lowercase letter."), 
     @Pattern(regexp = "(?=\\S+$)", message = "Password must contain no whitespace.") 
    }) 
    private String password; 

    @NotNull(message="Contact shouldnot be empty") 
    @Pattern(regexp = "[0-9]+", message="Contact should only contain numbers") 
    @Size(min=10, max=10) 
    private String contact; 

    @NotNull(message="Select atleast one skill from the list") 
    private List<String> studentSkills; 

    // Getter and Setter for studentId 
    public int getStudentId() { 
     return studentId; 
    } 
    public void setStudentId(int studentId) { 
     this.studentId = studentId; 
    } 

    // Getter and Setter for firstName 
    public String getFirstName() { 
     return firstName; 
    } 
    public void setFirstName(String firstName) { 
     this.firstName = firstName; 
    } 

    // Getter and Setter for lastName 
    public String getLastName() { 
     return lastName; 
    } 
    public void setLastName(String lastName) { 
     this.lastName = lastName; 
    } 

    // Getter and Setter for displayName 
    public String getDisplayName() { 
     return displayName; 
    } 
    public void setDisplayName(String displayName) { 
     this.displayName = displayName; 
    } 

    // Getter and Setter for DateOfBirth 
    public String getDateOfBirth() { 
     return dateOfBirth; 
    } 
    public void setDateOfBirth(String dateOfBirth) { 
     this.dateOfBirth = dateOfBirth; 
    } 

    // Getter and Setter for email 
    public String getEmail() { 
     return email; 
    } 
    public void setEmail(String email) { 
     this.email = email; 
    } 

    // Getter and Setter for password 
    public String getPassword() { 
     return password; 
    } 
    public void setPassword(String password) { 
     this.password = password; 
    } 

    // Getter and Setter for contact 
    public String getContact() { 
     return contact; 
    } 
    public void setContact(String contact) { 
     this.contact = contact; 
    } 

    // Getter and Setter for studentSkills 
    public List<String> getStudentSkills() { 
     return studentSkills; 
    } 
    public void setStudentSkills(List<String> studentSkills) { 
     this.studentSkills = studentSkills; 
    } 
} 

コントローラー:

@RequestMapping(value="/registration", method=RequestMethod.GET) 
public ModelAndView getRegForm() { 
    ModelAndView mv = new ModelAndView("registration","student",new Student()); 
    return mv; 
} 

@RequestMapping(value="/submitregistrationform", method=RequestMethod.POST) 
public ModelAndView submitRegForm(@Valid @ModelAttribute("student") Student student, BindingResult result) { 
    ModelAndView registrationView = new ModelAndView("registration"); 
    if(result.hasErrors()) { 
     return registrationView; 
    } else { 
     st.insertOrUpdate(student); 
     ModelAndView mv = new ModelAndView("login"); 
     return mv; 
    } 
} 

例外をソートする方法上の任意の提案ですか? Stringが動作するかどうかを調べるためにStringの長さを試しました。しかし、それはしませんでした。

答えて

0

日付の検証は正しくありません。日付が文字列形式であり、注釈がDATEデータ型をチェックすると、例外がスローされます。 日付のデータ型をStringからDATEに変更し、作業を開始しました。

関連する問題