/**
* Customized ErrorAttribute bean.
* We really need to find a cleaner way of handling these error messages.
*
* @return customized ErrorAttributes
*/
@Bean
public ErrorAttributes errorAttributes() {
return new DefaultErrorAttributes() {
@Override
public Map<String, Object> getErrorAttributes(
final RequestAttributes requestAttributes,
final boolean includeStackTrace) {
Map<String, Object> attributes = super
.getErrorAttributes(requestAttributes, includeStackTrace);
Throwable error = getError(requestAttributes);
if (error instanceof MethodArgumentNotValidException) {
MethodArgumentNotValidException ex =
((MethodArgumentNotValidException) error);
attributes.put("errors", ex.getMessage());
}
return attributes;
}
};
}
BootJpaApplication.java 文件源码
java
阅读 31
收藏 0
点赞 0
评论 0
项目:spring-boot-jpa
作者:
评论列表
文章目录