zoukankan      html  css  js  c++  java
  • springboot针对controller层返回对象设置全局返回json格式

    直接贴代码:

    import com.disney.wdpro.service.ecoupon.redemption.service.controller.interceptor.HttpStatusInterceptor;
    import com.disney.wdpro.service.ecoupon.redemption.service.controller.interceptor.OpenapiInterceptor;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.http.MediaType;
    import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
    import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    
    @Configuration
    public class ConfigInterceptor implements WebMvcConfigurer {
    
        @Bean("httpStatusInterceptor")
        public HttpStatusInterceptor getHttpStatusInterceptor() {
            return new HttpStatusInterceptor();
        }
    
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(getHttpStatusInterceptor()).addPathPatterns("/**");
        }
    
        @Override
        public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
            configurer.ignoreAcceptHeader(true)  // 这里一定要设置为true,才能覆盖原来的默认的xml format
                    .defaultContentType(MediaType.APPLICATION_JSON);
        }
    }

    end.

  • 相关阅读:
    转-文件批量重命名
    解决死锁之路(终结篇)
    Python批量修改文件名
    Android AudioTrack分析
    Android Audio介绍
    Android GNSS介绍
    Android HIDL介绍
    【vue】类和内联样式绑定
    【vue】计算属性
    svn post-commit不能同步
  • 原文地址:https://www.cnblogs.com/zhuwenjoyce/p/13631239.html
Copyright © 2011-2022 走看看