org.springframework.validation.BeanPropertyBindingResult Exception

早过忘川 提交于 2020-01-13 11:09:18

问题


Hi I am a new to spring framework. I have done a small example where I tried to validate my input field using spring validation api. This is the code

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

}

But when I submit the from with blank value its given me the following error

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 ]

回答1:


plz change the line in your code which is shown bellow...

public String insertdata(
    @ModelAttribute("applicationForm") @Valid ApplicationFormBean    applicationFormBean,
    BindingResult result,
    Model model,
    @RequestParam("file") MultipartFile file)


来源:https://stackoverflow.com/questions/24802681/org-springframework-validation-beanpropertybindingresult-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!