本文整理汇总了Java中javax.validation.ConstraintViolationException.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java ConstraintViolationException.getMessage方法的具体用法?Java ConstraintViolationException.getMessage怎么用?Java ConstraintViolationException.getMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.validation.ConstraintViolationException
的用法示例。
在下文中一共展示了ConstraintViolationException.getMessage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleConstraintViolationException
import javax.validation.ConstraintViolationException; //导入方法依赖的package包/类
@ExceptionHandler(ConstraintViolationException.class)
public ResponseEntity<List<String>> handleConstraintViolationException(ConstraintViolationException e) {
if (e.getMessage() == null) {
List<String> constraints = e.getConstraintViolations().stream()
.map(constraintViolation -> new StringBuffer()
.append("Le champ ")
.append(constraintViolation.getPropertyPath().toString())
.append(" ")
.append(constraintViolation.getMessage())
.append(" (valeur : ")
.append(constraintViolation.getInvalidValue().toString())
.append(")")
.toString())
.collect(Collectors.toList());
return new ResponseEntity<>(constraints, HttpStatus.BAD_REQUEST);
}
return new ResponseEntity<>(Collections.singletonList(e.getMessage()), HttpStatus.BAD_REQUEST);
}
示例2: ValidationJsonException
import javax.validation.ConstraintViolationException; //导入方法依赖的package包/类
/**
* Constructor from errors.
*
* @param validation
* validation exception containing errors.
*/
public ValidationJsonException(final ConstraintViolationException validation) {
this(validation.getMessage());
validation.getConstraintViolations()
.forEach(e -> errors.computeIfAbsent(getPropertyPath(e), k -> new ArrayList<>()).add(serializeHibernateValidationError(e)));
}