0

アノテーションフォームの動作に基づいて春の検証を取得するのに苦労しました。

これをspring-servlet.xmlに追加しました

<context:component-scan base-package="com.it.controller" /> (すべてのコントローラーを含むパッケージ)

<context:component-scan base-package="com.it.form" /> (すべてのフォーム クラスを含むパッケージ)

パッケージ com.it.form のクラス email :

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";
}

}

フォームを送信すると、メール入力を空白のままにしても、常に /success ページにリダイレクトされるようです...

私が何かを逃したかどうかはわかりません よろしくお願いします:)

4

1 に答える 1