码迷,mamicode.com
首页 > Web开发 > 详细

fastJson设置接口只接受json格式数据

时间:2018-12-12 19:39:36      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:flight   tpm   value   media   for   ring   binding   return   arc   

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)
    {}

}

  

fastJson设置接口只接受json格式数据

标签:flight   tpm   value   media   for   ring   binding   return   arc   

原文地址:https://www.cnblogs.com/achengmu/p/10110516.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!