org.springframework.validation.annotation.Validated Java Examples
The following examples show how to use
org.springframework.validation.annotation.Validated.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdminDepartmentFromController.java From Spring-MVC-Blueprints with MIT License | 6 votes |
@RequestMapping(method=RequestMethod.POST) public RedirectView submitForm(Model model, @Validated @ModelAttribute("deptForm") DepartmentForm deptForm, BindingResult bindingResult){ model.addAttribute("deptForm", deptForm); RedirectView redirectView = new RedirectView(); redirectView.setContextRelative(true); redirectView.setUrl("/smp/admin_add_department.html"); List<Tbldepartment> depts = reportService.getAllDepartment(); model.addAttribute("depts", depts); if(bindingResult.hasErrors()) { deptForm = new DepartmentForm(); model.addAttribute("deptForm", deptForm); } else{ managementService.addDepartment(deptForm); deptForm = new DepartmentForm(); model.addAttribute("deptForm", deptForm); } return redirectView; }
Example #2
Source File: AdminCourseFormController.java From Spring-MVC-Blueprints with MIT License | 6 votes |
@RequestMapping(method=RequestMethod.POST) public RedirectView submitForm(Model model, @Validated @ModelAttribute("courseForm") CourseForm courseForm, BindingResult bindingResult){ model.addAttribute("courseForm", courseForm); RedirectView redirectView = new RedirectView(); redirectView.setContextRelative(true); redirectView.setUrl("/smp/admin_add_course.html"); List<Tblcourses> courses = reportService.getAllCourses(); model.addAttribute("courses", courses); references(model); if(bindingResult.hasErrors()) { courseForm = new CourseForm(); model.addAttribute("courseForm", courseForm); } else{ managementService.addCourse(courseForm); courseForm = new CourseForm(); model.addAttribute("courseForm", courseForm); } return redirectView; }
Example #3
Source File: AdminFacultyFormController.java From Spring-MVC-Blueprints with MIT License | 6 votes |
@RequestMapping(method=RequestMethod.POST) public RedirectView submitForm(Model model, @Validated @ModelAttribute("facultyForm") FacultyForm facultyForm, BindingResult bindingResult){ model.addAttribute("facultyForm", facultyForm); RedirectView redirectView = new RedirectView(); redirectView.setContextRelative(true); redirectView.setUrl("/smp/admin_add_faculty.html"); List<Tblfaculty> faculty = reportService.getAllFaculty(); model.addAttribute("faculty", faculty); references(model); if(bindingResult.hasErrors()) { facultyForm = new FacultyForm(); model.addAttribute("facultyForm", facultyForm); } else{ managementService.addFaculty(facultyForm); facultyForm = new FacultyForm(); model.addAttribute("facultyForm", facultyForm); } return redirectView; }
Example #4
Source File: StoreSeckillController.java From yshopmall with Apache License 2.0 | 6 votes |
@Log("发布") @ApiOperation(value = "发布") @PutMapping(value = "/yxStoreSeckill") @PreAuthorize("@el.check('admin','YXSTORESECKILL_ALL','YXSTORESECKILL_EDIT')") public ResponseEntity update(@Validated @RequestBody YxStoreSeckill resources){ if(ObjectUtil.isNotNull(resources.getStartTimeDate())){ resources.setStartTime(OrderUtil. dateToTimestamp(resources.getStartTimeDate())); } if(ObjectUtil.isNotNull(resources.getEndTimeDate())){ resources.setStopTime(OrderUtil. dateToTimestamp(resources.getEndTimeDate())); } if(ObjectUtil.isNull(resources.getId())){ resources.setAddTime(String.valueOf(OrderUtil.getSecondTimestampTwo())); return new ResponseEntity(yxStoreSeckillService.save(resources),HttpStatus.CREATED); }else{ yxStoreSeckillService.saveOrUpdate(resources); return new ResponseEntity(HttpStatus.NO_CONTENT); } }
Example #5
Source File: AdminLoginController.java From Spring-MVC-Blueprints with MIT License | 6 votes |
@RequestMapping(method=RequestMethod.POST) public RedirectView submitForm(Model model, @Validated @ModelAttribute LoginForm adminLoginForm, BindingResult bindingResult){ model.addAttribute("adminLoginForm", adminLoginForm); RedirectView redirectView = new RedirectView(); redirectView.setContextRelative(true); if(bindingResult.hasErrors()) { adminLoginForm = new LoginForm(); redirectView.setUrl("/smp/admin_login.html"); model.addAttribute("adminLoginForm", adminLoginForm); } else{ Login login = new Login(); login.setUserName(adminLoginForm.getUsername()); login.setPassWord(adminLoginForm.getPassword()); if(loginService.isAdminUser(login.getUserName(), login.getPassWord())){ redirectView.setUrl("/smp/admin_pending.html"); }else{ adminLoginForm = new LoginForm(); redirectView.setUrl("/smp/admin_login.html"); } } return redirectView; }
Example #6
Source File: StoreOrderController.java From yshopmall with Apache License 2.0 | 6 votes |
@ApiOperation(value = "退款") @PostMapping(value = "/yxStoreOrder/refund") @PreAuthorize("@el.check('admin','YXSTOREORDER_ALL','YXSTOREORDER_EDIT')") public ResponseEntity refund(@Validated @RequestBody YxStoreOrder resources) { yxStoreOrderService.refund(resources); //模板消息通知 try { YxWechatUserDto wechatUser = generator.convert(wechatUserService.getOne(new QueryWrapper<YxWechatUser>().eq("uid",resources.getUid())),YxWechatUserDto.class); if (ObjectUtil.isNotNull(wechatUser)) { //公众号与小程序打通统一公众号模板通知 if (StrUtil.isNotBlank(wechatUser.getOpenid())) { templateService.refundSuccessNotice(resources.getOrderId(), resources.getPayPrice().toString(),wechatUser.getOpenid(), OrderUtil.stampToDate(resources.getAddTime().toString())); } } } catch (Exception e) { log.info("当前用户不是微信用户不能发送模板消息哦!"); } return new ResponseEntity(HttpStatus.NO_CONTENT); }
Example #7
Source File: TaskDefineController.java From batch-scheduler with MIT License | 6 votes |
@RequestMapping(method = RequestMethod.PUT) @ResponseBody public String update(@Validated TaskDefineEntity taskDefineEntity, BindingResult bindingResult, HttpServletResponse response, HttpServletRequest request) { if (bindingResult.hasErrors()) { for (ObjectError m : bindingResult.getAllErrors()) { response.setStatus(421); return Hret.error(421, m.getDefaultMessage(), null); } } RetMsg retMsg = taskDefineService.update(parse(request)); if (!retMsg.checkCode()) { response.setStatus(retMsg.getCode()); return Hret.error(retMsg); } return Hret.success(retMsg); }
Example #8
Source File: AdminLoginController.java From Spring-MVC-Blueprints with MIT License | 6 votes |
@RequestMapping(method=RequestMethod.POST) public RedirectView submitForm(Model model, @Validated @ModelAttribute LoginForm adminLoginForm, BindingResult bindingResult){ model.addAttribute("adminLoginForm", adminLoginForm); RedirectView redirectView = new RedirectView(); redirectView.setContextRelative(true); if(bindingResult.hasErrors()) { adminLoginForm = new LoginForm(); redirectView.setUrl("/smp/admin_login.html"); model.addAttribute("adminLoginForm", adminLoginForm); } else{ Login login = new Login(); login.setUserName(adminLoginForm.getUsername()); login.setPassWord(adminLoginForm.getPassword()); if(loginService.isAdminUser(login)){ redirectView.setUrl("/smp/admin_pending.html"); }else{ adminLoginForm = new LoginForm(); redirectView.setUrl("/smp/admin_login.html"); } } return redirectView; }
Example #9
Source File: FrpFileController.java From frpMgr with MIT License | 6 votes |
/** * 保存frp */ @RequiresPermissions("frp:frp:edit") @PostMapping(value = "save") @ResponseBody public String save(@Validated Frp frp) { // 类型 frp.setType(ClientType.FILE.value); //判断是否存在项目名称,二级域名,远程端口一样的; Frp isExist = frpService.isExist(frp.getProjectName(), frp.getFrpDomainSecond(), String.valueOf(frp.getServerId()), frp.getFrpRemotePort()); if (isExist == null) { frp.setUserId(UserUtils.getUser().getId()); frpService.save(frp); } else { return renderResult(Global.TRUE, text("项目名、二级域名冲突或远程端口冲突!")); } return renderResult(Global.TRUE, text("保存frp成功!")); }
Example #10
Source File: BaseController.java From SuperBoot with MIT License | 5 votes |
@ApiOperation(value = "锁定TOKEN", notes = "锁定TOKEN,需要指定角色才有此权限") @RequestMapping(value = "/locked", method = RequestMethod.POST) public BaseResponse lockedToken(@RequestBody @Validated Token token) throws BaseException { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); BaseResponse op = pubService.checkUserIsManager("" + request.getHeader(BaseConstants.TOKEN_KEY)); if (StatusCode.AUTHORIZATION_OPERATION.getCode() == op.getCode()) { return pubService.locked(token); } else { return op; } }
Example #11
Source File: ResourceSortRestApi.java From mogu_blog_v2 with Apache License 2.0 | 5 votes |
@AuthorityVerify @ApiOperation(value = "获取资源分类列表", notes = "获取资源分类列表", response = String.class) @PostMapping("/getList") public String getList(@Validated({GetList.class}) @RequestBody ResourceSortVO resourceSortVO, BindingResult result) { ThrowableUtils.checkParamArgument(result); return ResultUtil.result(SysConf.SUCCESS, resourceSortService.getPageList(resourceSortVO)); }
Example #12
Source File: GrayGroupController.java From AthenaServing with Apache License 2.0 | 5 votes |
/** * 服务订阅查看 * * @param body * @param result * @return */ @RequestMapping(value = "/consumer", method = RequestMethod.GET) public Response<QueryPagingListResponseBody> consumer(@Validated QueryCustomDetailRequestBody body, BindingResult result) { if (result.hasErrors()) { return new Response<>(SystemErrCode.ERRCODE_INVALID_PARAMETER, result.getFieldError().getDefaultMessage()); } return this.grayServiceImpl.consumer(body); }
Example #13
Source File: PmsBrandController.java From mall-swarm with Apache License 2.0 | 5 votes |
@ApiOperation(value = "添加品牌") @RequestMapping(value = "/create", method = RequestMethod.POST) @ResponseBody public CommonResult create(@Validated @RequestBody PmsBrandParam pmsBrand, BindingResult result) { CommonResult commonResult; int count = brandService.createBrand(pmsBrand); if (count == 1) { commonResult = CommonResult.success(count); } else { commonResult = CommonResult.failed(); } return commonResult; }
Example #14
Source File: SysRoleController.java From spring-boot-plus with Apache License 2.0 | 5 votes |
/** * 添加系统角色 */ @PostMapping("/add") @RequiresPermissions("sys:role:add") @OperationLog(name = "添加系统角色", type = OperationLogType.ADD) @ApiOperation(value = "添加系统角色", response = ApiResult.class) public ApiResult<Boolean> addSysRole(@Validated(Add.class) @RequestBody SysRole sysRole) throws Exception { boolean flag = sysRoleService.saveSysRole(sysRole); return ApiResult.result(flag); }
Example #15
Source File: TableEntityController.java From das with Apache License 2.0 | 5 votes |
/** * 2、批量新建 */ @RequestMapping(value = "/adds", method = RequestMethod.POST) public ServiceResult<String> adds(@Validated(AddTableEntity.class) @RequestBody List<TaskTable> list, @CurrentUser LoginUser user, Errors errors) throws Exception { if (CollectionUtils.isEmpty(list)) { return ServiceResult.fail("参数为空"); } ValidateResult validateRes = tableEntityService.validatePermision(user, list.get(0), errors) .addAssert(() -> tableEntityService.addTaskTableList(user, list)).validate(); if (!validateRes.isValid()) { return ServiceResult.fail(validateRes.getSummarize()); } return ServiceResult.success(); }
Example #16
Source File: MethodValidationInterceptor.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Determine the validation groups to validate against for the given method invocation. * <p>Default are the validation groups as specified in the {@link Validated} annotation * on the containing target class of the method. * @param invocation the current MethodInvocation * @return the applicable validation groups as a Class array */ protected Class<?>[] determineValidationGroups(MethodInvocation invocation) { Validated validatedAnn = AnnotationUtils.findAnnotation(invocation.getMethod(), Validated.class); if (validatedAnn == null) { validatedAnn = AnnotationUtils.findAnnotation(invocation.getThis().getClass(), Validated.class); } return (validatedAnn != null ? validatedAnn.value() : new Class<?>[0]); }
Example #17
Source File: UserRestController.java From spring-boot-doma2-sample with Apache License 2.0 | 5 votes |
/** * ユーザーを更新します。 * * @param */ @PutMapping(value = "/{userId}") public Resource update(@PathVariable("userId") Long userId, @Validated @RequestBody User inputUser, Errors errors) { // 入力エラーがある場合 if (errors.hasErrors()) { throw new ValidationErrorException(errors); } // 1件更新する inputUser.setId(userId); User user; { //TODO 本来ならサービスで実装すべき //created_byなどがAPIからは取得できないので、DBから取得して、パラメータで更新内容を上書きしている user = userService.findById(inputUser.getId()); ModelMapper modelMapper = DefaultModelMapperFactory.create(); modelMapper.getConfiguration().setPropertyCondition(Conditions.isNotNull()); modelMapper.map(inputUser, user); } user = userService.update(user); Resource resource = resourceFactory.create(); resource.setData(Arrays.asList(user)); resource.setMessage(getMessage(MESSAGE_SUCCESS)); return resource; }
Example #18
Source File: CubaMethodValidationInterceptor.java From cuba with Apache License 2.0 | 5 votes |
protected Class<?>[] determineValidationGroups(MethodInvocation invocation) { Validated validatedAnn = AnnotationUtils.findAnnotation(invocation.getMethod(), Validated.class); if (validatedAnn == null) { validatedAnn = AnnotationUtils.findAnnotation(invocation.getThis().getClass(), Validated.class); } return (validatedAnn != null ? validatedAnn.value() : new Class<?>[0]); }
Example #19
Source File: DatabaseController.java From das with Apache License 2.0 | 5 votes |
private ServiceResult<String> addDataBase(@Validated(AddDataBase.class) @RequestBody DataBaseInfo dataBaseInfo, @CurrentUser LoginUser user, Errors errors) throws Exception { dataBaseInfo.setUpdateUserNo(user.getUserNo()); ValidateResult validateRes = databaseService.validatePermision(user, errors) .addAssert(() -> dataBaseDao.getCountByName(dataBaseInfo.getDbname()) == 0, dataBaseInfo.getDbname() + "已经存在!") .addAssert(() -> databaseService.addDataBaseInfo(user, dataBaseInfo)).validate(); if (!validateRes.isValid()) { return ServiceResult.fail(validateRes.getSummarize()); } return databaseService.addDataCenter(user, Lists.newArrayList(dataBaseInfo)); }
Example #20
Source File: ServiceController.java From AthenaServing with Apache License 2.0 | 5 votes |
/** * 复制服务 * * @param body * @param result * @return */ @RequestMapping(value = "/copy", method = RequestMethod.POST) public Response<ServiceDetailResponseBody> copy(@Validated @RequestBody CopyServiceRequestBody body, BindingResult result) { if (result.hasErrors()) { return new Response<>(SystemErrCode.ERRCODE_INVALID_PARAMETER, result.getFieldError().getDefaultMessage()); } return this.serviceImpl.copy(body); }
Example #21
Source File: MenuController.java From cms with Apache License 2.0 | 5 votes |
@Log("删除菜单") @ApiOperation("删除菜单") @DeleteMapping("/delete") // @PreAuthorize("@el.check('menu:del')") public Map<String, Object> delete(@Validated @RequestBody @NotNull Set<Long> ids) { menuService.delete(ids); return MapUtils.create().set("code", 0); }
Example #22
Source File: AbstractMessageConverterMethodArgumentResolver.java From java-technology-stack with MIT License | 5 votes |
/** * Validate the binding target if applicable. * <p>The default implementation checks for {@code @javax.validation.Valid}, * Spring's {@link org.springframework.validation.annotation.Validated}, * and custom annotations whose name starts with "Valid". * @param binder the DataBinder to be used * @param parameter the method parameter descriptor * @since 4.1.5 * @see #isBindExceptionRequired */ protected void validateIfApplicable(WebDataBinder binder, MethodParameter parameter) { Annotation[] annotations = parameter.getParameterAnnotations(); for (Annotation ann : annotations) { Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class); if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) { Object hints = (validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann)); Object[] validationHints = (hints instanceof Object[] ? (Object[]) hints : new Object[] {hints}); binder.validate(validationHints); break; } } }
Example #23
Source File: SysDictTypeRestApi.java From mogu_blog_v2 with Apache License 2.0 | 5 votes |
@AuthorityVerify @OperationLogger(value = "批量删除字典类型") @ApiOperation(value = "批量删除字典类型", notes = "批量删除字典类型", response = String.class) @PostMapping("/deleteBatch") public String delete(HttpServletRequest request, @Validated({Delete.class}) @RequestBody List<SysDictTypeVO> sysDictTypeVoList, BindingResult result) { // 参数校验 ThrowableUtils.checkParamArgument(result); return sysDictTypeService.deleteBatchSysDictType(sysDictTypeVoList); }
Example #24
Source File: AliPayController.java From yshopmall with Apache License 2.0 | 5 votes |
@Log("配置支付宝") @ApiOperation("配置支付宝") @PutMapping public ResponseEntity<Object> payConfig(@Validated @RequestBody AlipayConfig alipayConfig){ alipayConfig.setId(1L); alipayService.update(alipayConfig); return new ResponseEntity<>(HttpStatus.OK); }
Example #25
Source File: PeonyController.java From smart-admin with MIT License | 5 votes |
@ApiOperation(value = "导出全部", notes = "@author 卓大") @PostMapping("/peony/export/all") public void exportAll(@RequestBody @Validated PeonyQueryDTO queryDTO, HttpServletResponse response) { //查询数据 List<PeonyExcelVO> peonyList = peonyService.queryAllExportData(queryDTO); //导出操作 ExportParams ex = new ExportParams("牡丹花", "Sheet1"); Workbook workbook = ExcelExportUtil.exportExcel(ex, PeonyExcelVO.class, peonyList); downloadExcel("牡丹花", workbook, response); }
Example #26
Source File: ProjectController.java From das with Apache License 2.0 | 5 votes |
/** * 3、更新project */ @RequestMapping(value = "/update", method = RequestMethod.PUT) public ServiceResult<String> update(@Validated(UpdateProject.class) @RequestBody Project project, @CurrentUser LoginUser user, Errors errors) throws Exception { project.setUpdate_user_no(user.getUserNo()); Project oldProject = projectDao.getProjectByID(project.getId()); ProjectView oldProjectView = projectDao.getProjectViewById(project.getId()); ValidateResult validateRes = projectService.validatePermision(user, project, errors) .addAssert(() -> projectService.isNotExistByName(project), project.getName() + " 已存在!") .addAssert(() -> projectService.isNotExistByAppId(project), "APPID:" + project.getApp_id() + " 已存在!") .addAssert(() -> projectService.updateProject(project)).validate(); if (!validateRes.isValid()) { return ServiceResult.fail(validateRes.getSummarize()); } return projectService.updateDataCenter(user, oldProject, oldProjectView, project); }
Example #27
Source File: SysConfigController.java From RuoYi-Vue with MIT License | 5 votes |
/** * 新增参数配置 */ @PreAuthorize("@ss.hasPermi('system:config:add')") @Log(title = "参数管理", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@Validated @RequestBody SysConfig config) { if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config))) { return AjaxResult.error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在"); } config.setCreateBy(SecurityUtils.getUsername()); return toAjax(configService.insertConfig(config)); }
Example #28
Source File: SpaceController.java From AnyMock with Apache License 2.0 | 5 votes |
@PostMapping("/space/insert") @ResponseBody public BaseResponse create( @Validated(value = {SpaceBO.Insert.class}) @RequestBody SpaceBO spaceBO ) { spaceService.create(spaceBO); return new BaseResponse(translator.translate(ResultCode.SUCCESS_CREATE_SPACE)); }
Example #29
Source File: SysUserController.java From spring-boot-plus with Apache License 2.0 | 5 votes |
/** * 修改系统用户 */ @PostMapping("/update") @RequiresPermissions("sys:user:update") @OperationLog(name = "修改系统用户", type = OperationLogType.UPDATE) @ApiOperation(value = "修改系统用户", response = ApiResult.class) public ApiResult<Boolean> updateSysUser(@Validated(Update.class) @RequestBody SysUser sysUser) throws Exception { boolean flag = sysUserService.updateSysUser(sysUser); return ApiResult.result(flag); }
Example #30
Source File: GrayConfigController.java From AthenaServing with Apache License 2.0 | 5 votes |
/** * 查询灰度配置历史列表 * * @param body * @param result * @return */ @RequestMapping(value = "/historyList", method = RequestMethod.GET) public Response<QueryPagingListResponseBody> historyList(@Validated ServiceGrayConfigHistoryListRequestBody body, BindingResult result) { if (result.hasErrors()) { return new Response<>(SystemErrCode.ERRCODE_INVALID_PARAMETER, result.getFieldError().getDefaultMessage()); } return this.serviceConfigImpl.findServiceGrayConfigHistoryList(body); }