我在春天有网络应用程序。我有这样的形式:
<form:form action="submitFormAdd" id="formId" method="GET" modelAttribute="myCandidate">
<label for="nameInput" path="name"> Name</label>
<form:input path="name" id="nameInput"></form:input>
<form:errors path="name" cssclass="error"></form:errors>
</form:form>
所以处理程序:
@RequestMapping("/submitFormAdd")
public String submitFormAdd(Model model
,@ModelAttribute @Valid Candidate myCandidate
,BindingResult result
,@ModelAttribute("skillsIdList") Set<Skill> skills
,@ModelAttribute("vacanciesForCandidate") Set<Vacancy> vacanciesForCandidate){
if(result.hasErrors()) {
return "candidateDetailsAdd";
}
return "candidateMenu";
}
如果我输入少于 10 个符号 result.hasErrors() 等于 true,但我在 jsp 页面上看不到错误(模型中的类:
public class Candidate {
@Size(min=10)
private String name;
//getters and setters
}
如何解决?
PS属性(/ui/src/main/resources/messages.properties):
Size.myCandidate.name = more size please
NotNull = Field cannot be left blank
NotEmpty = not empty
和配置:
public class UiConfig {
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("messages");
return messageSource;
}
}