本文整理了Java中javax.validation.ConstraintViolationException.getLocalizedMessage()
方法的一些代码示例,展示了ConstraintViolationException.getLocalizedMessage()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ConstraintViolationException.getLocalizedMessage()
方法的具体详情如下:
包路径:javax.validation.ConstraintViolationException
类名称:ConstraintViolationException
方法名:getLocalizedMessage
暂无
代码示例来源:origin: junneyang/xxproject
@ExceptionHandler({ ConstraintViolationException.class })
public ResponseEntity<Object> handleConstraintViolation(final ConstraintViolationException ex, final WebRequest request) {
logger.info(ex.getClass().getName());
//
final List<String> errors = new ArrayList<String>();
for (final ConstraintViolation<?> violation : ex.getConstraintViolations()) {
errors.add(violation.getRootBeanClass().getName() + " " + violation.getPropertyPath() + ": " + violation.getMessage());
}
final ApiError apiError = new ApiError(HttpStatus.BAD_REQUEST, ex.getLocalizedMessage(), errors);
return new ResponseEntity<Object>(apiError, new HttpHeaders(), apiError.getStatus());
}
代码示例来源:origin: com.netflix.genie/genie-web
/**
* Handle constraint violation exceptions.
*
* @param response The HTTP response
* @param cve The exception to handle
* @throws IOException on error in sending error
*/
@ExceptionHandler(ConstraintViolationException.class)
public void handleConstraintViolation(
final HttpServletResponse response,
final ConstraintViolationException cve
) throws IOException {
final StringBuilder builder = new StringBuilder();
if (cve.getConstraintViolations() != null) {
for (final ConstraintViolation<?> cv : cve.getConstraintViolations()) {
if (builder.length() != 0) {
builder.append(NEW_LINE);
}
builder.append(cv.getMessage());
}
}
this.countException(cve);
log.error(cve.getLocalizedMessage(), cve);
response.sendError(HttpStatus.PRECONDITION_FAILED.value(), builder.toString());
}
内容来源于网络,如有侵权,请联系作者删除!