zoukankan      html  css  js  c++  java
  • fastJson设置接口只接受json格式数据

    spring-mvc/servlet.xml

    <mvc:annotation-driven>
            <mvc:message-converters register-defaults="true">
                <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/html;charset=UTF-8</value>
                            <value>application/json;charset=UTF-8</value>
                        </list>
                    </property>
                    <property name="features">
                        <list>
                            <value>WriteMapNullValue</value>
                            <value>QuoteFieldNames</value>
                            <value>WriteDateUseDateFormat</value>
                            <!-- 禁用fastjson循环引用检测 -->
                            <value>DisableCircularReferenceDetect</value>
                        </list>
                    </property>
                </bean>
            </mvc:message-converters>
        </mvc:annotation-driven>
    

      

    controller:

    @RestController
    @RequestMapping("/api/flights")
    public class ApiFlightsController {
    
        @Autowired
        private RedisService redisService;
    
        /**
         * 查询
         * @param flightSearchForm
         * @param bindingResult
         * @return
         */
        @RequestMapping(value = "/search", method = RequestMethod.POST,  produces = {"application/json;charset=UTF-8"})
        public ResultUtil search(@Valid @RequestBody FlightSearchForm flightSearchForm, BindingResult bindingResult)
        {}
    
    }
    

      

  • 相关阅读:
    MySQL体系结构
    详解MySQL的用户密码过期/锁定解锁功能
    MySQL5.7 密码安全策略
    Python终端如何输出彩色字体
    flashback
    PXC 部署前置检查
    CentOS7 安装docker
    CentOS7 安装ifconfig
    CentOS 7 网络配置
    VMware虚拟机克隆Linux系统引起的网卡问题
  • 原文地址:https://www.cnblogs.com/achengmu/p/10110516.html
Copyright © 2011-2022 走看看