方法1.用getbytes()转换编码
@RequestMapping(value="/search/{key}", method = {RequestMethod.GET})
public String searchFaceListIndex(@PathVariable(value="key") String key, Map<String, Object> result) throws UnsupportedEncodingException {
key = new String(key.getBytes("ISO-8859-1"), "utf8");
return "searchFaceList";
}
方法2.修改tomcat配置:
(部署环境下的tomcat和eclipse下的tomcat 的 server.xml是不一样的) 参考: http://www.cnblogs.com/zhonghan/p/3339150.html
第一:code
@RequestMapping(value = "/query/{keyword}", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
public String query(@PathVariable String keyword) {
}
第二:tomcat server.xml 中
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>
注意:如果使用eclipse启动tomcat时,需要将workspace下面 的server.xml 中的Connector也添加URIEncoding="UTF-8"