Cha*_*rma 4 spring hibernate spring-mvc spring-mvc-initbinders
嗨,我是spring框架的新手。我做了一个小例子,尝试使用spring验证api验证输入字段。这是代码
@RequestMapping(value = "/applicationFormSubmit", method = RequestMethod.POST)
public String insertdata( @ModelAttribute("applicationForm") @Valid ApplicationFormBean applicationFormBean, @RequestParam("file") MultipartFile file, BindingResult result,Model model)
{
if(result.hasErrors())
{
return "applicationForm";
}
try {
Blob blob = Hibernate.createBlob(file.getInputStream());
// applicationFormBean..setFilename(file.getOriginalFilename());
applicationFormBean.setSignature(blob);
// applicationFormBean.setContentType(file.getContentType());
} catch (IOException e) {
e.printStackTrace();
}
applicationFormUserService.insertApplicationData(applicationFormBean);
return "applicationForm";
}
Run Code Online (Sandbox Code Playgroud)
但是当我用空白值提交from时,它给了我以下错误
Field error in object 'applicationForm' on field 'applicantName': rejected value []; codes [NotEmpty.applicationForm.applicantName,NotEmpty.applicantName,NotEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [applicationForm.applicantName,applicantName]; arguments []; default message [applicantName]]; default message [Please enter your nnnn.]
Field error in object 'applicationForm' on field 'applicantName': rejected value []; codes [Size.applicationForm.applicantName,Size.applicantName,Size.java.lang.String,Size]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [applicationForm.applicantName,applicantName]; arguments []; default message [applicantName],20,2]; default message [this is worng ]
Run Code Online (Sandbox Code Playgroud)
请在下面的代码中更改行...
public String insertdata(
@ModelAttribute("applicationForm") @Valid ApplicationFormBean applicationFormBean,
BindingResult result,
Model model,
@RequestParam("file") MultipartFile file)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9951 次 |
| 最近记录: |