springboot2.0拦截器配置

springboot中配置拦截的三种方式:
第一种:继承 WebMvcConfigurerAdapter类
在SpringBoot2.0及Spring 5.0 WebMvcConfigurerAdapter已被废弃springboot2.0拦截器配置
第二种:继承WebMvcConfigurationSupport类
springboot2.0拦截器配置这种方式会出现返回的数据为XML格式

(1)响应头
springboot2.0拦截器配置(2)返回值
springboot2.0拦截器配置
针对这种情况我们的解决方案:
1.在前端请求头中加入参数accept = application/json
2.web控制层@RequestMapping中中添加produces = { “application/json; charset=UTF-8” }
3.在拦截器配置中加入内容协商配置代码(根据WebMvcAutoConfiguration改写的)
springboot2.0拦截器配置

第三种:实现WebMvcConfigurer接口,
springboot2.0拦截器配置 上述三种方式中第一种已经过时不推荐使用,第二种配置比较繁琐,第三种比较简单推荐使用