@Test public void multi() throws Exception { String response = mockMvc.perform(post("/validator/multi") .param("firstName", "Benedict") .param("lastName", "Jin") .param("country", "Earth")) .andReturn().getResponse().getContentAsString(); assertTrue(response.contains(ERROR_PASSWORD_EMPTY)); assertTrue(response.contains(ERROR_MIDDLE_NAME_EMPTY)); }
@RequestMapping("/multi") public String multi(@Valid @ModelAttribute("user") User user, BindingResult userErrors, @Valid @ModelAttribute("userModel") UserModel userModel, BindingResult userModelErrors) { StringBuilder strBuilder = new StringBuilder(); if (userErrors.hasErrors()) { strBuilder.append(ValidationUtils.getErrorInfos(userErrors)).append(" "); } if (userModelErrors.hasErrors()) { strBuilder.append(ValidationUtils.getErrorInfos(userModelErrors)); } if (strBuilder.toString().length() > 0) { return strBuilder.toString(); } return "redirect:/success"; }
ValidatorController { @RequestMapping("/multi") public String multi(@Valid @ModelAttribute("user") User user, BindingResult userErrors, @Valid @ModelAttribute("userModel") UserModel userModel, BindingResult userModelErrors) { StringBuilder strBuilder = new StringBuilder(); if (userErrors.hasErrors()) { strBuilder.append(ValidationUtils.getErrorInfos(userErrors)).append(" "); } if (userModelErrors.hasErrors()) { strBuilder.append(ValidationUtils.getErrorInfos(userModelErrors)); } if (strBuilder.toString().length() > 0) { return strBuilder.toString(); } return "redirect:/success"; } }
ValidatorController { @RequestMapping("/multi") public String multi(@Valid @ModelAttribute("user") User user, BindingResult userErrors, @Valid @ModelAttribute("userModel") UserModel userModel, BindingResult userModelErrors) { StringBuilder strBuilder = new StringBuilder(); if (userErrors.hasErrors()) { strBuilder.append(ValidationUtils.getErrorInfos(userErrors)).append(" "); } if (userModelErrors.hasErrors()) { strBuilder.append(ValidationUtils.getErrorInfos(userModelErrors)); } if (strBuilder.toString().length() > 0) { return strBuilder.toString(); } return "redirect:/success"; }  }
ValidatorController { @RequestMapping("/multi") public String multi(@Valid @ModelAttribute("user") User user, BindingResult userErrors, @Valid @ModelAttribute("userModel") UserModel userModel, BindingResult userModelErrors) { StringBuilder strBuilder = new StringBuilder(); if (userErrors.hasErrors()) { strBuilder.append(ValidationUtils.getErrorInfos(userErrors)).append(" "); } if (userModelErrors.hasErrors()) { strBuilder.append(ValidationUtils.getErrorInfos(userModelErrors)); } if (strBuilder.toString().length() > 0) { return strBuilder.toString(); } return "redirect:/success"; }  @ApiOperation( value = "获得商品信息", notes = "获取商品信息(用于数据同步)", httpMethod = "POST", response = String.class, produces = MediaType.APPLICATION_JSON_VALUE) @Produces(MediaType.APPLICATION_JSON_VALUE) @Consumes(MediaType.APPLICATION_JSON_VALUE) @ApiResponses(value = { @ApiResponse(code = 200, message = "商品信息", response = String.class), @ApiResponse(code = 201, message = "ErrorType.errorCheckToken" + "(token验证失败)", response = String.class), @ApiResponse(code = 202, message = "ErrorType.error500" + "(系统错误)", response = String.class)}) @RequestMapping(value = "/save", method = RequestMethod.POST) String save(@ApiParam(required = true)
                       @Validated({Second.class})
                       /*@RequestBody*/ @ModelAttribute UserModel userModel, BindingResult result); @RequestMapping(value = "/update", method = RequestMethod.POST) String update(@Validated({First.class, Second.class}) UserModel userModel, BindingResult result); @RequestMapping(value = "/update/order", method = RequestMethod.POST) String register(@Validated(Group.class) User user, BindingResult result); @RequestMapping("/multi") String multi(@Valid @ModelAttribute("user") User user, BindingResult userErrors,
                        @Valid @ModelAttribute("userModel") UserModel userModel, BindingResult userModelErrors); }
ValidatorController { @RequestMapping("/multi") public String multi(@Valid @ModelAttribute("user") User user, BindingResult userErrors, @Valid @ModelAttribute("userModel") UserModel userModel, BindingResult userModelErrors) { StringBuilder strBuilder = new StringBuilder(); if (userErrors.hasErrors()) { strBuilder.append(ValidationUtils.getErrorInfos(userErrors)).append(" "); } if (userModelErrors.hasErrors()) { strBuilder.append(ValidationUtils.getErrorInfos(userModelErrors)); } if (strBuilder.toString().length() > 0) { return strBuilder.toString(); } return "redirect:/success"; }  @ApiOperation( value = "获得商品信息", notes = "获取商品信息(用于数据同步)", httpMethod = "POST", response = String.class, produces = MediaType.APPLICATION_JSON_VALUE) @Produces(MediaType.APPLICATION_JSON_VALUE) @Consumes(MediaType.APPLICATION_JSON_VALUE) @ApiResponses(value = { @ApiResponse(code = 200, message = "商品信息", response = String.class), @ApiResponse(code = 201, message = "ErrorType.errorCheckToken" + "(token验证失败)", response = String.class), @ApiResponse(code = 202, message = "ErrorType.error500" + "(系统错误)", response = String.class)}) @RequestMapping(value = "/save", method = RequestMethod.POST) String save(@ApiParam(required = true)
                       @Validated({Second.class})
                       /*@RequestBody*/ @ModelAttribute UserModel userModel, BindingResult result); @RequestMapping(value = "/update", method = RequestMethod.POST) String update(@Validated({First.class, Second.class}) UserModel userModel, BindingResult result); @RequestMapping(value = "/update/order", method = RequestMethod.POST) String register(@Validated(Group.class) User user, BindingResult result); @RequestMapping("/multi") String multi(@Valid @ModelAttribute("user") User user, BindingResult userErrors,
                        @Valid @ModelAttribute("userModel") UserModel userModel, BindingResult userModelErrors);  }