mirror of https://gitee.com/maxjhandsome/pig
commit
30e7c369e5
|
@ -69,7 +69,7 @@ pig
|
||||||
|
|
||||||
3. 不接受`功能请求`的 [issue](https://gitee.com/log4j/pig/issues),功能请求可能会被直接关闭。
|
3. 不接受`功能请求`的 [issue](https://gitee.com/log4j/pig/issues),功能请求可能会被直接关闭。
|
||||||
|
|
||||||
4. mail: <a href="mailto:pig4cloud@qq.com">pig4cloud@qq.com</a> | <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=2270033969&site=qq&menu=yes"> QQ: 2270033969</a>
|
4. mail: <a href="mailto:pig4cloud@qq.com">pig4cloud@qq.com</a> | <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=3130998334&site=qq&menu=yes"> QQ: 3130998334</a>
|
||||||
|
|
||||||
#### 公开课
|
#### 公开课
|
||||||
|
|
||||||
|
|
|
@ -52,17 +52,29 @@ public class GlobalExceptionHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* validation Exception
|
* validation Exception (以json形式传参)
|
||||||
*
|
*
|
||||||
* @param exception
|
* @param exception
|
||||||
* @return R
|
* @return R
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler({MethodArgumentNotValidException.class, BindException.class})
|
@ExceptionHandler({MethodArgumentNotValidException.class})
|
||||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
public R bodyValidExceptionHandler(MethodArgumentNotValidException exception) {
|
public R bodyValidExceptionHandler(MethodArgumentNotValidException exception) {
|
||||||
List<FieldError> fieldErrors = exception.getBindingResult().getFieldErrors();
|
List<FieldError> fieldErrors = exception.getBindingResult().getFieldErrors();
|
||||||
log.warn(fieldErrors.get(0).getDefaultMessage());
|
log.warn(fieldErrors.get(0).getDefaultMessage());
|
||||||
return R.failed(fieldErrors.get(0).getDefaultMessage());
|
return R.failed(fieldErrors.get(0).getDefaultMessage());
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* validation Exception (以form-data形式传参)
|
||||||
|
*
|
||||||
|
* @param exception
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@ExceptionHandler({BindException.class})
|
||||||
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
|
public R bindExceptionHandler(BindException exception) {
|
||||||
|
List<FieldError> fieldErrors = exception.getBindingResult().getFieldErrors();
|
||||||
|
log.warn(fieldErrors.get(0).getDefaultMessage());
|
||||||
|
return R.failed(fieldErrors.get(0).getDefaultMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue