3
如何在不提供命令對象的情況下驗證簡單表單(一個輸入字段)並顯示錯誤?我的簡單形式是:Spring MVC:無需@ModelAttribute /「命令對象」的簡單驗證
<form id="verify" action="check.html">
<input name="code"/>
<form:errors path="code" />
<input type="submit" value="ok" />
</form>
控制器處理程序方法如下。我需要產生的錯誤信息和到位的form:errors
@RequestMapping("/check.html")
public String check(@RequestParam(value="code") String code) {
if(!isGood(code)) {
// How to bind some error messages for `code` ?
return "fail"; // fail page
}
return "ok";
}