需要在spring-mvc.xml配置文件中加入:
<!-- 开启注解 --> <mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/plain;charset=UTF-8</value> <value>text/html;charset=UTF-8</value> <value>application/json;charset=UTF-8</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven>
若不加上面两行,则浏览器访问时会出现乱码。另外的解决方式是访问方法上加:
@RequestMapping(value = "/deleteOrder", method = RequestMethod.POST,produces = "text/plain;charset=UTF-8")//加上produces
@ResponseBody
public String deleteOrder(HttpServletRequest request){}