客户端在服务器上发送(实现无关紧要):
/path/items/ + urlencode(id,SOME_ENCODING)
考虑结果URL将是:
/path/items/my%2Fkey
因此我在服务器上:
@RequestMapping(value = "/path/items/{identifier}",method = RequestMethod.GET)
public Item get(@PathVariable String identifier) {
try {
return DAO.getItemByIdentifier(URLDecoder.decode(identifier,SOME_ENCODING))
}
catch (UnsupportedEncodingException e) {
...
}
在内部有没有办法在Spring中做到这一点?我的意思是标识符已经解码,所以我可以:
@RequestMapping(value = "/path/items/{identifier}",method = RequestMethod.GET)
public Item get(@PathVariable String identifier) {
return DAO.getitemByidentifier(identifier); // already decoded!
}
最佳答案
您应该在server.xml中的tomcat连接器中设置URIEncoding.
原文链接:https://www.f2er.com/spring/432342.html看看:http://tomcat.apache.org/tomcat-5.5-doc/config/http.html
//编辑:
您还可以尝试在web.xml(或java类)中设置编码过滤器,如:
Spring/Rest @PathVariable character encoding