The Springmvc I use, transmits a json in the controller layer to the foreground, the background display is no problem, the Chinese is displayed normally and arrives at the foreground
Chinese becomes a question mark.
Later, it was found that because @ResponseBody was used to return json in the controller, and the implementation class of @ResponseBody in the spring source code found that its default encoding was iso-8859-1, and the encoding used in the project was utf-8, so the Chinese will appear. gibberish.
Here I use annotations to solve:
js is as follows:
$.ajax({
url: 'sort/allSort',
dataType: 'json',
type: 'post',
success: function(data){...}
)}
@RequestMapping(value="/"allSort.do", produces = "application/json; charset=utf-8")
Method 2: Solve it globally, configure it once, and use it globally. Recommended Use
Add the following configuration to the spring core configuration file:
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
OK, problem solved
If you still can't solve it: Complete solution