Spring mvc 的多表单验证错误处理



public ModelAndView index(@ModelAttribute("registerSMGMethod1Step1Form") RegisterSMGMethod1Step1Form registerSMGMethod1Step1Form,  BindingResult bindingResult1,@ModelAttribute("registerSMGMethod2Step1Form") RegisterSMGMethod2Step1Form registerSMGMethod2Step1Form,BindingResult bindingResult2,ModelAndView model, HttpServletRequest request) {
		model.setViewName("customer/smg-step1");
		//处理method1_bingSMG foward过来的bindingResult.
		if(request.getAttribute("bindingResult")!=null){
			String userType= (String)request.getAttribute("userType");
			List<ObjectError> allerrors=(((BindingResult)request.getAttribute("bindingResult")).getAllErrors());
			for(int idx=0;idx<allerrors.size();idx++){
				if("SMGMethod1".equals(userType)){
					bindingResult1.addError(allerrors.get(idx));
				}else if("SMGMethod2".equals(userType)){
					bindingResult2.addError(allerrors.get(idx));
				}
			}
		}

你可能感兴趣的:(spring mvc)