@Test public void save() throws Exception { UserModel userModel = new UserModel(); userModel.setUserName("yuzhouwan"); userModel.setContent(null); Long future = System.currentTimeMillis() + 10_0000L; String response = mockMvc.perform(post("/validator/save") .param("id", "0x5555") .param("account", "101") .param("userName", "yuzhouwan") .param("email", "yuzhouwan@asdf.com") .param("future", future + "")) .andReturn().getResponse().getContentAsString(); assertTrue(response.contains(ERROR_CONTENT)); assertTrue(response.contains(ACCOUNT_MAX)); assertTrue(response.contains(USER_NAME_FORMAT)); }
@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) public String save(@ApiParam(required = true) @Validated({Second.class}) @ModelAttribute UserModel userModel, BindingResult result) { if (result.hasErrors()) { return ValidationUtils.getErrorInfos(result); } return "redirect:/success"; }
ValidatorController { @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) public String save(@ApiParam(required = true) @Validated({Second.class}) @ModelAttribute UserModel userModel, BindingResult result) { if (result.hasErrors()) { return ValidationUtils.getErrorInfos(result); } return "redirect:/success"; } }
ValidatorController { @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) public String save(@ApiParam(required = true) @Validated({Second.class}) @ModelAttribute UserModel userModel, BindingResult result) { if (result.hasErrors()) { return ValidationUtils.getErrorInfos(result); } return "redirect:/success"; }  }
ValidatorController { @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) public String save(@ApiParam(required = true) @Validated({Second.class}) @ModelAttribute UserModel userModel, BindingResult result) { if (result.hasErrors()) { return ValidationUtils.getErrorInfos(result); } 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 { @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) public String save(@ApiParam(required = true) @Validated({Second.class}) @ModelAttribute UserModel userModel, BindingResult result) { if (result.hasErrors()) { return ValidationUtils.getErrorInfos(result); } 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);  }