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

前端之家收集整理的这篇文章主要介绍了fastJson设置接口只接受json格式数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_502_3@

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

}
@H_502_3@

猜你在找的Json相关文章