406 Not Acceptable

In Spring MVC, if @ResponseBody is used to return a json object to the foreground, the following error will sometimes be reported:

406 Not Acceptable

 

reason:

The data type requested by the client is inconsistent with the type of data received from the server.

 

Solution:

1. Import the third-party fastjson package, such as: fastjson-1.1.34.jar

2. Add the Spring configuration file:

<mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
            <!-- Avoid downloading files when returning JSON when IE executes AJAX -->
            <bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326753204&siteId=291194637