package com.ctsi.g5c.common.exception;
import com.ctsi.g5c.common.web.R;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.util.List;
/**
* @author shao
*/
@RestControllerAdvice
public class ExceptionAdvice {
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseBody
public R<Object> handleBindException(MethodArgumentNotValidException ex) {
List<ObjectError> errors = ex.getBindingResult().getAllErrors();
StringBuilder builder = new StringBuilder("[");
errors.forEach(error -> {
builder.append(error.getDefaultMessage());
});
return R.fail(builder.append("]").toString());
}
}
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone:GMT+8