1.方法上面的RequestMapping要加上红色的部分。
@ResponseBody
@RequestMapping(value = "/search", produces = {"application/json;charset=UTF-8"})
public String search(HttpServletRequest request, HttpServletResponse response) {
2.推荐方式:在springmvc-servlet.xml[或者其他名称]里面更改<mvc:annotation-driven />的配置,如下:
把<mvc:annotation-driven />改成下面:
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="UTF-8" />
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
时间: 2024-11-08 10:28:37