本文整理了Java中org.springframework.validation.BindException.getAllErrors()
方法的一些代码示例,展示了BindException.getAllErrors()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BindException.getAllErrors()
方法的具体详情如下:
包路径:org.springframework.validation.BindException
类名称:BindException
方法名:getAllErrors
暂无
代码示例来源:origin: qiurunze123/miaosha
@ExceptionHandler(value=Exception.class)
public ResultGeekQ<String> exceptionHandler(HttpServletRequest request , Exception e){
e.printStackTrace();
if(e instanceof GlobleException){
GlobleException ex= (GlobleException)e;
return ResultGeekQ.error(ex.getStatus());
}else if( e instanceof BindException){
BindException ex = (BindException) e ;
List<ObjectError> errors = ex.getAllErrors();
ObjectError error = errors.get(0);
String msg = error.getDefaultMessage();
/**
* 打印堆栈信息
*/
logger.error(String.format(msg, msg));
return ResultGeekQ.error(SESSION_ERROR);
}else {
return ResultGeekQ.error(SYSTEM_ERROR);
}
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void modelAndView() throws Exception {
BindException bindException = new BindException(new Object(), "target");
bindException.reject("errorCode");
ModelAndView mav = new ModelAndView("viewName");
mav.addObject("attrName", "attrValue");
mav.addObject(BindingResult.MODEL_KEY_PREFIX + "attrName", bindException);
this.mvcResult.setMav(mav);
this.handler.handle(this.mvcResult);
assertValue("ModelAndView", "View name", "viewName");
assertValue("ModelAndView", "View", null);
assertValue("ModelAndView", "Attribute", "attrName");
assertValue("ModelAndView", "value", "attrValue");
assertValue("ModelAndView", "errors", bindException.getAllErrors());
}
代码示例来源:origin: org.springframework.boot/spring-boot
private ExceptionDetails getBindValidationExceptionDetails(Throwable rootFailure) {
BindValidationException validationException = findCause(rootFailure,
BindValidationException.class);
if (validationException != null) {
BindException target = findCause(rootFailure, BindException.class);
List<ObjectError> errors = validationException.getValidationErrors()
.getAllErrors();
return new ExceptionDetails(errors, target, validationException);
}
org.springframework.validation.BindException bindException = findCause(
rootFailure, org.springframework.validation.BindException.class);
if (bindException != null) {
List<ObjectError> errors = bindException.getAllErrors();
return new ExceptionDetails(errors, bindException.getTarget(), bindException);
}
return null;
}
代码示例来源:origin: openmrs/openmrs-core
@Test
public void shouldFailIfGivenNull() {
validator.validate(null, errors);
Assert.assertTrue(errors.hasErrors());
Assert.assertEquals("error.general", errors.getAllErrors().get(0).getCode());
}
代码示例来源:origin: com.clusterra/clusterra-iam-rest
@ExceptionHandler(BindException.class)
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
@ResponseBody
public List<ObjectError> handle(BindException exception) {
return exception.getAllErrors();
}
代码示例来源:origin: com.clusterra/pmbok-rest-api
@ExceptionHandler(BindException.class)
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
@ResponseBody
public List<ObjectError> handle(BindException exception) {
return exception.getAllErrors();
}
代码示例来源:origin: com.clusterra/clusterra-pmbok-rest-api
@ExceptionHandler(BindException.class)
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
@ResponseBody
public List<ObjectError> handle(BindException exception) {
return exception.getAllErrors();
}
代码示例来源:origin: com.clusterra/clusterra-pmbok-rest-api
@ExceptionHandler(BindException.class)
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
@ResponseBody
public List<ObjectError> handle(BindException exception) {
return exception.getAllErrors();
}
代码示例来源:origin: com.clusterra/iam-rest
@ExceptionHandler(BindException.class)
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
@ResponseBody
public List<ObjectError> handle(BindException exception) {
return exception.getAllErrors();
}
代码示例来源:origin: com.clusterra/pmbok-rest-api
@ExceptionHandler(BindException.class)
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
@ResponseBody
public List<ObjectError> handle(BindException exception) {
return exception.getAllErrors();
}
代码示例来源:origin: codeabovelab/haven-platform
@ExceptionHandler(BindException.class)
@ResponseStatus(BAD_REQUEST)
@ResponseBody
public UiError bindErrorHandler(BindException bindException) {
log.error("Can't process request", bindException);
return createResponse(bindException.getMessage(), bindException.getAllErrors().toString(), BAD_REQUEST);
}
代码示例来源:origin: com.soento/soento-web
/**
* 参数绑定异常处理
*
* @param cause 异常
* @return 响应结果
*/
@ExceptionHandler(BindException.class)
@ResponseBody
public RespData handleBindException(BindException cause, HttpServletRequest request) {
// 输出错误信息
log.info("== 请求参数异常 ==");
List<ObjectError> errors = cause.getAllErrors();
for (ObjectError error : errors) {
log.info(error.toString());
}
log.info(cause.getMessage(), cause);
return validator(errors, request);
}
代码示例来源:origin: zaiyunduan123/springboot-seckill
@ExceptionHandler(value = Exception.class)//拦截所有异常
public Result<String> exceptionHandler(HttpServletRequest request, Exception e){
e.printStackTrace();
if(e instanceof GlobalException) {
GlobalException ex = (GlobalException)e;
return Result.error(ex.getCodeMsg());
}else if(e instanceof BindException) {
BindException ex = (BindException)e;
List<ObjectError> errors = ex.getAllErrors();//绑定错误返回很多错误,是一个错误列表,只需要第一个错误
ObjectError error = errors.get(0);
String msg = error.getDefaultMessage();
return Result.error(CodeMsg.BIND_ERROR.fillArgs(msg));//给状态码填充参数
}else {
return Result.error(CodeMsg.SERVER_ERROR);
}
}
}
代码示例来源:origin: jkazama/sample-boot-micro
/** Controllerへのリクエスト紐付け例外 */
@ExceptionHandler(BindException.class)
public ResponseEntity<Map<String, String[]>> handleBind(BindException e) {
log.warn(e.getMessage());
return new ErrorHolder(msg, locale(), convert(e.getAllErrors()).list()).result(HttpStatus.BAD_REQUEST);
}
代码示例来源:origin: hfbin/Seckill
@ExceptionHandler(value=Exception.class)
public Result<String> exceptionHandler(HttpServletRequest request, Exception e){
e.printStackTrace();
if(e instanceof HfbinException) {
HfbinException ex = (HfbinException)e;
return Result.error(ex.getCm());
}else if(e instanceof BindException) {
BindException ex = (BindException)e;
List<ObjectError> errors = ex.getAllErrors();
ObjectError error = errors.get(0);
String msg = error.getDefaultMessage();
return Result.error(CodeMsg.BIND_ERROR.fillArgs(msg));
}else {
return Result.error(CodeMsg.SERVER_ERROR);
}
}
}
代码示例来源:origin: b2stry/seckill
@ExceptionHandler(value = Exception.class)
public Result<String> exceptionHandler(HttpServletRequest request, Exception e) {
e.printStackTrace();
if (e instanceof GlobalException) {
GlobalException ex = (GlobalException) e;
return Result.error(ex.getCodeMsg());
} else if (e instanceof BindException) {
BindException ex = (BindException) e;
List<ObjectError> errors = ex.getAllErrors();
ObjectError error = errors.get(0);
String msg = error.getDefaultMessage();
return Result.error(CodeMsg.BIND_ERROR.fillArgs(msg));
} else {
return Result.error(CodeMsg.SERVER_ERROR);
}
}
}
代码示例来源:origin: spring-projects/spring-security-oauth2-boot
@Override
public boolean matches(Object item) {
BindException ex = (BindException) ((Exception) item).getCause();
ObjectError error = ex.getAllErrors().get(0);
boolean messageMatches = message.equals(error.getDefaultMessage());
if (field == null) {
return messageMatches;
}
String fieldErrors = ((FieldError) error).getField();
return messageMatches && fieldErrors.equals(field);
}
代码示例来源:origin: 1144388620lq/skill
@ExceptionHandler(value=Exception.class)
public Result<String> exceptionHandler(HttpServletRequest request, Exception e){
e.printStackTrace();
if(e instanceof GlobalException) {
GlobalException ex = (GlobalException)e;
return Result.error(ex.getCm());
}else if(e instanceof BindException) {
BindException ex = (BindException)e;
List<ObjectError> errors = ex.getAllErrors();
ObjectError error = errors.get(0);
String msg = error.getDefaultMessage();
return Result.error(CodeMsg.BIND_ERROR.fillArgs(msg));
}else {
return Result.error(CodeMsg.SERVER_ERROR);
}
}
}
代码示例来源:origin: cloudfoundry-community/autosleep
@Test
public void test_handleBindException_returns_errors() throws Exception {
BindException be = mock(BindException.class);
ObjectError fakeError1 = new ObjectError("orgEnrollmentConfig", "fakeErrorMessage1");
ObjectError fakeError2 = new ObjectError("orgEnrollmentConfig", "fakeErrorMessage2");
when(be.getAllErrors()).thenReturn(Arrays.asList(fakeError1, fakeError2));
HttpServletResponse response = mock(HttpServletResponse.class);
ResponseEntity<List<ObjectError>> errors = autoEnrollmentController.handleBindException(be,
response);
assertTrue(errors.getBody() != null && errors.getBody().size() == 2);
assertTrue(errors.getStatusCode() == HttpStatus.BAD_REQUEST);
}
代码示例来源:origin: com.hotels/circus-train-vacuum-tool
public static void main(String[] args) throws Exception {
// below is output *before* logging is configured so will appear on console
logVersionInfo();
try {
SpringApplication.exit(new SpringApplicationBuilder(VacuumTool.class)
.properties("spring.config.location:${config:null}")
.properties("spring.profiles.active:" + Modules.REPLICATION)
.properties("instance.home:${user.home}")
.properties("instance.name:${source-catalog.name}_${replica-catalog.name}")
.bannerMode(Mode.OFF)
.registerShutdownHook(true)
.build()
.run(args));
} catch (BeanCreationException e) {
if (e.getMostSpecificCause() instanceof BindException) {
printVacuumToolHelp(((BindException) e.getMostSpecificCause()).getAllErrors());
}
throw e;
}
}
内容来源于网络,如有侵权,请联系作者删除!