2013-05-29 2 views
0

주석 폼 작업을 기반으로 스프링 유효성 검사를하는 데 약간의 문제가 있습니다. 스프링 mvc 주석을 사용한 폼 유효성 검사

는 내 스프링 servlet.xml 파일이 추가

<context:component-scan base-package="com.it.controller" /> (내 모든 제어기를 포함하는 패키지)

<context:component-scan base-package="com.it.form" /> (내 모든 형태의 클래스를 포함하는 패키지)

com.it.form 패키지의 전자 메일 :

public class email { 
@NotEmpty 
@Email 
private String email; 

public String getEmail() { 
    return email; 
} 

public void setEmail(String email) { 
    this.email = email; 
} 

public email() { 
    email = ""; 
    // TODO Auto-generated constructor stub 
} 

}

형태 :

<body> 
<form:form method="post" action="" commandName='email'> 
    <div class="requestEmail"> 
     <form:label path="email">Entrez votre email:</form:label> 
     <form:input path="email" /> 
     <form:errors path="email" /> 
    </div> 
    <div> 
     <input type="submit" value="VALIDER" /> 
    </div> 
</form:form> 

컨트롤러 : 나는 항상/성공에 리디렉션하고 내 양식을 제출할 때

@Controller 
@SessionAttributes 
public class passwordController { 

/* 
* ########################################################## 
* 
* Print & valid form Email 
* 
* ########################################################## 
*/ 

@RequestMapping(value = "/passwordChange.mvc", method = RequestMethod.GET) 
public String get(final ModelMap model) { 

    email email= new email(); 
    model.addAttribute("email", email); 
    return "passwordChangeRequestEmail"; // jsp form 
} 

@RequestMapping(value = "/passwordChange.mvc", method = RequestMethod.POST) 
public String post(final ModelMap model, 
     @ModelAttribute("email") @Valid final email email, 
     final BindingResult result) { 

    if (result.hasErrors()) { 
     return "error"; 
    } 
    return "success"; 
} 

}

보인다 페이지, 비록 내가 내가 뭔가 사전에 감사합니다 :) 당신은 당신의 서블릿 컨텍스트 파일에

<mvc:annotation-driven /> 

을 추가하고 최대 절전 모드 검사기와 같은 검증을 가져와야합니다

+1

아마도 JSR303 주석 처리를위한 Hibernate 유효성 검사기 종속성'hibernate-validator'가 있을까요? –

+0

예. 나는 해결책을 발견, 나는 을 포함하지 않았다. :(나는 가 충분하다고 생각했다. – MinionKing

답변

0

을 놓친

몰라 경우 ... 빈 이메일 입력을두고 당신의 classpath에서.

관련 문제