use of org.springframework.validation.FieldError in project ArachneCentralAPI by OHDSI.
the class StudyStatusController method create.
@ApiOperation(value = "Register new study status.", hidden = true)
@RequestMapping(value = "/api/v1/admin/study-statuses", method = RequestMethod.POST)
public JsonResult<StudyStatusDTO> create(@RequestBody @Valid CreateStudyStatusDTO studyStatusDTO, BindingResult binding) throws NotExistException, NotUniqueException, PermissionDeniedException {
JsonResult<StudyStatusDTO> result;
if (binding.hasErrors()) {
result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
for (FieldError fieldError : binding.getFieldErrors()) {
result.getValidatorErrors().put(fieldError.getField(), fieldError.getDefaultMessage());
}
} else {
StudyStatus studyStatus = conversionService.convert(studyStatusDTO, StudyStatus.class);
studyStatus = studyStatusService.create(studyStatus);
result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
result.setResult(conversionService.convert(studyStatus, StudyStatusDTO.class));
}
return result;
}
use of org.springframework.validation.FieldError in project production_ssm by megagao.
the class OrderController method insert.
@RequestMapping(value = "/insert", method = RequestMethod.POST)
@ResponseBody
private CustomResult insert(@Valid COrder cOrder, BindingResult bindingResult) throws Exception {
CustomResult result;
if (bindingResult.hasErrors()) {
FieldError fieldError = bindingResult.getFieldError();
System.out.println(fieldError.getDefaultMessage());
return CustomResult.build(100, fieldError.getDefaultMessage());
}
if (orderService.get(cOrder.getOrderId()) != null) {
result = new CustomResult(0, "该订单编号已经存在,请更换订单编号!", null);
} else {
result = orderService.insert(cOrder);
}
return result;
}
use of org.springframework.validation.FieldError in project production_ssm by megagao.
the class UserController method updateAll.
@RequestMapping(value = "/update_all")
@ResponseBody
private CustomResult updateAll(@Valid SysUser user, BindingResult bindingResult) throws Exception {
CustomResult result;
if (bindingResult.hasErrors()) {
FieldError fieldError = bindingResult.getFieldError();
return CustomResult.build(100, fieldError.getDefaultMessage());
}
if (userService.findByUserNameAndId(user.getUsername(), user.getId()).size() > 0) {
return CustomResult.build(101, "该用户名已经存在,请更换用户名!");
}
result = userService.updateAll(user);
return result;
}
use of org.springframework.validation.FieldError in project production_ssm by megagao.
the class UserController method insert.
@RequestMapping(value = "/insert", method = RequestMethod.POST)
@ResponseBody
private CustomResult insert(@Valid SysUser user, BindingResult bindingResult) throws Exception {
CustomResult result;
if (bindingResult.hasErrors()) {
FieldError fieldError = bindingResult.getFieldError();
return CustomResult.build(100, fieldError.getDefaultMessage());
}
if (userService.findByUserNameAndId(user.getUsername(), user.getId()).size() > 0) {
return CustomResult.build(101, "该用户名已经存在,请更换用户名!");
} else if (userService.get(user.getId()) != null) {
return CustomResult.build(101, "该用户编号已经存在,请更换用户编号!");
}
result = userService.insert(user);
return result;
}
use of org.springframework.validation.FieldError in project production_ssm by megagao.
the class PMeasureCheckController method insert.
/*
*此处的method可以取两个值,
*一个是RequestMethod.GET,一个是RequestMethod.POST,
*就是请求该方法使用的模式,是get还是post,即参数提交的方法
*ajax或者form表单提交数据有两种方法,即get和post。
*/
@RequestMapping(value = "/insert", method = RequestMethod.POST)
@ResponseBody
private CustomResult insert(@Valid ProcessMeasureCheck processMeasureCheck, BindingResult bindingResult) throws Exception {
CustomResult result;
if (bindingResult.hasErrors()) {
FieldError fieldError = bindingResult.getFieldError();
return CustomResult.build(100, fieldError.getDefaultMessage());
}
result = pMeasureCheckService.insert(processMeasureCheck);
return result;
}
Aggregations