BootJpaApplication.java 文件源码

java
阅读 31 收藏 0 点赞 0 评论 0

项目:spring-boot-jpa 作者:
/**
 * 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;
        }
    };
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号