【发布时间】:2021-04-07 04:15:27
【问题描述】:
我在应用程序级别使用GenericExceptionHandling
@ControllerAdvice
public class GlobalExceptionHandler {
// Handle the DataIntegrityViolationException
@ExceptionHandler(DataIntegrityViolationException.class)
public ResponseEntity<?> customDataIntegrityViolationException
(DataIntegrityViolationException exception) {
String message = "This {key} is already exist";
ErrorDetails errorDetals = new ErrorDetails(new Date(), message, exception.getCause().getMessage());
return new ResponseEntity<Object>(errorDetals, HttpStatus.UNPROCESSABLE_ENTITY);
}
}
我想获取导致错误的键的名称。 IE。 {钥匙}。我用谷歌搜索但没有得到任何解决我问题的答案。如果有人做过这种工作,请提出一种方法。
【问题讨论】:
标签: java spring spring-boot hibernate spring-mvc