美文网首页
Spring Boot记录

Spring Boot记录

作者: 2efa470dd3ae | 来源:发表于2019-07-12 11:14 被阅读0次

1.全局异常捕获

@RestControllerAdvice
public class ExceptionHandler{
  /**
     * 请求方式不支持
     */
    @ExceptionHandler({HttpRequestMethodNotSupportedException.class})
    public Result handleException(HttpRequestMethodNotSupportedException e) {
        log.error(e.getMessage(), e);
        return R.fail(ResultCode.COMMON_NOT_SUPPORT);
    }
}

2.拦截器

1.使用注解@ConConfiguration配置拦截器
2.继承WebMvcConfigConfiguerAdapter
3.重写addInterceptors添加需要的拦截器地址
4.拦截器继承HandlerInInterceptor

3.@JSONView注解

1.作用:返回不同数据添加注解如:有的User需要返回密码,有的User不需要返回密码。
2.参数为接口类,需要在Model中get方法上添加该注解。
3.然后在相应的Controller接口上添加该注解。

4.

相关文章

网友评论

      本文标题:Spring Boot记录

      本文链接:https://www.haomeiwen.com/subject/jfkytctx.html