本文整理汇总了Java中org.springframework.data.rest.core.RepositoryConstraintViolationException类的典型用法代码示例。如果您正苦于以下问题:Java RepositoryConstraintViolationException类的具体用法?Java RepositoryConstraintViolationException怎么用?Java RepositoryConstraintViolationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RepositoryConstraintViolationException类属于org.springframework.data.rest.core包,在下文中一共展示了RepositoryConstraintViolationException类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleConstraintViolationException
import org.springframework.data.rest.core.RepositoryConstraintViolationException; //导入依赖的package包/类
/**
* Method to handle with {@link RepositoryConstraintViolationException} and return response
* with http status and {@link Message} with error information.
*
* @param e the {@link RepositoryConstraintViolationException} to handle with
* @return the {@link ResponseEntity} with {@link Message}, http headers and status
*/
@ExceptionHandler({RepositoryConstraintViolationException.class})
ResponseEntity handleConstraintViolationException(RepositoryConstraintViolationException e) {
List<Message> messages = new ArrayList<>();
for (FieldError error : e.getErrors().getFieldErrors()) {
messages.add(new Message(messageSourceAccessor.getMessage(error.getDefaultMessage()), MessageType.ERROR, error.getField()));
}
return new ResponseEntity(messages, new HttpHeaders(), HttpStatus.CONFLICT);
}