第一步:在需要访问的controller层的接口上添加@ResponseBody注释 如下所示
加上以上配置之后重启服务 中文正常显示
@Controller
@RequestMapping("myportalAndParty")
public class MyportalAndParty {
@RequestMapping(value = "QueryPartyByMyportal", method = { RequestMethod.POST, RequestMethod.GET })
@ResponseBody
public String QueryPartyByMyportal(HttpServletRequest request, HttpServletResponse response){
return null;
}
}
第二部:在spring-servlet.xml中添加如下配置
<bean
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<bean
class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
<bean
class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
</list>
</property>
</bean>
</list>
</property>
</bean>
第三步:在第二部的后面加上下面的一行配置 必须加上 不然以上的配置不会生效
<!-- 默认的注解映射的支持 -->
<mvc:annotation-driven />
加上以上配置之后重启服务 中文正常显示