1. 在自定义的config配置类中,重写configureContentNegotiation方法
  2. @Bean
    public WebMvcConfigurer webMvcConfigurer(){
    return new WebMvcConfigurer() {
    /**
    * 自定义内容协商策略
    * @param configurer
    */
    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
    // 自定义策略
    // ContentNegotiationConfigurer mediaTypes(@Nullable Map<String, MediaType> mediaTypes)
    Map<String, MediaType> map = new HashMap<>();
    map.put("json", MediaType.APPLICATION_JSON);
    map.put("xml", MediaType.APPLICATION_ATOM_XML);
    map.put("gg",MediaType.parseMediaType("applicaion/x-z"));
    // 指定基于参数的解析类型
    ParameterContentNegotiationStrategy negotiationStrategy = new ParameterContentNegotiationStrategy(map);
    // 指定基于请求头的解析
    HeaderContentNegotiationStrategy headerContentNegotiationStrategy = new HeaderContentNegotiationStrategy();
    configurer.strategies(Arrays.asList(negotiationStrategy));
    }
    };
    }

SpringBoot 自定义内容协商策略 configureContentNegotiation的更多相关文章

  1. HttpClient_自定义cookie策略

    实际使用client的过程中,会遇到一种情况,如cookie的Key为空的,此时默认的cookie的策略处理cookie是会报错. 这时咱可以通过重写cookiestore策略来解决如: /** * ...

  2. SpringBoot自定义拦截器实现IP白名单功能

    SpringBoot自定义拦截器实现IP白名单功能 转载请注明源地址:http://www.cnblogs.com/funnyzpc/p/8993331.html 首先,相关功能已经上线了,且先让我先 ...

  3. Springboot中实现策略模式+工厂模式

    策略模式和工厂模式相信大家都比较熟悉,但是大家有没有在springboot中实现策略和工厂模式? 具体策略模式和工厂模式的UML我就不给出来了,使用这个这两个模式主要是防止程序中出现大量的IF ELS ...

  4. SpringBoot自定义错误信息,SpringBoot适配Ajax请求

    SpringBoot自定义错误信息,SpringBoot自定义异常处理类, SpringBoot异常结果处理适配页面及Ajax请求, SpringBoot适配Ajax请求 ============== ...

  5. SpringBoot自定义错误页面,SpringBoot 404、500错误提示页面

    SpringBoot自定义错误页面,SpringBoot 404.500错误提示页面 SpringBoot 4xx.html.5xx.html错误提示页面 ====================== ...

  6. springboot自定义错误页面

    springboot自定义错误页面 1.加入配置: @Bean public EmbeddedServletContainerCustomizer containerCustomizer() { re ...

  7. SpringBoot自定义Filter

    SpringBoot自定义Filter SpringBoot自动添加了OrderedCharacterEncodingFilter和HiddenHttpMethodFilter,当然我们可以自定 义F ...

  8. springboot 自定义LocaleResolver切换语言

    springboot 自定义LocaleResolver切换语言 我们在做项目的时候,往往有很多项目需要根据用户的需要来切换不同的语言,使用国际化就可以轻松解决. 我们可以自定义springboor中 ...

  9. Spring Cloud Netflix Ribbon详细介绍及自定义规则策略

    之前文章我们介绍了如何配置具有Ribbon轮询机制的负载均衡策略的消费者,这次来具体了解一下Ribbon的一些细节,以及如何自定义负载均衡策略等. 说一下Ribbon实现负载均衡的大致思路.它通过用@ ...

随机推荐

  1. v4l2数据获取流程

    V4L2数据获取流程 整个过程相关的数据结构有如下几个: struct v4l2_capability m_cap; /* 驱动能力 */ struct v4l2_format m_fmt; /* 数 ...

  2. CodeForces 519B A and B and Compilation Errors (超水题)

    这道题是超级水的,在博客上看有的人把这道题写的很麻烦. 用 Python 的话是超级的好写,这里就奉上 C/C++ 的AC. 代码如下: #include <cstdio> #includ ...

  3. PAT 乙级 1003. 我要通过!(20) (C语言描述)

    "答案正确"是自动判题系统给出的最令人欢喜的回复.本题属于PAT的"答案正确"大派送 -- 只要读入的字符串满足下列条件,系统就输出"答案正确&quo ...

  4. 在 k8s 中的 jenkins 集成 sonarqube 实现代码质量检查

    不乱于心,不困于情,不畏将来,不念过往,如此安好 --<不宠无惊过一生>丰子恺 概述 关于在 k8s 中安装 jenkins 和 sornarqube 可以查看下面的文章: 在 k8s 中 ...

  5. Ubuntu 18.04 server安装+搭建Seacms v10.1网站

    0x00 写在前面 以前我天真的认为,ubuntu Desktop会安装了,server就无所谓了,其实完全不然,server还是有一些坑点的. 之所以选择Seacms搭建网站,是因为这个SeaCMS ...

  6. INFO client.RMProxy: Connecting to ResourceManager at hadoop

    1.查看防火墙是否没关闭. 2.用jps 命令查看是否没有启动resourcemanager

  7. 【初体验】valgrind分析程序性能

    wget https://fossies.org/linux/misc/valgrind-3.15.0.tar.bz2 tar -jxvf valgrind-3.15.0.tar.bz2 cd val ...

  8. selenium获取cookies并持久化登陆

    selenium获取cookies并持久化登陆 需求背景: ​ 这几天需要写一个接口,用来批量上传数据,最开始考虑的是 UI 自动化,然后选值的时候自动化难以判别,最终选择 接口 自动化. ​ 然后操 ...

  9. vector自实现(一)

    vector.h: #ifndef __Vector__H__ #define __Vector__H__ typedef int Rank; #define DEFAULT_CAPACITY 3 t ...

  10. golang中for循环的常用用法

    package main import "fmt" func main() { //printFormula() // 打印九九乘法表 //printLeftTriangle() ...