客戶端服務器上的發送(實施無所謂):在何處以及如何解碼@PathVariable
/path/items/ + urlencode(id, SOME_ENCODING)
考慮結果的網址爲:
/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) {
...
}
有沒有辦法在內部做到這一點?我的意思是得到標識已解碼的,所以我可以只:
@RequestMapping(value = "/path/items/{identifier}", method = RequestMethod.GET)
public Item get(@PathVariable String identifier) {
return DAO.getitemByidentifier(identifier); // already decoded!
}
這是自動完成的。當我向'/ my%20key'發送請求時,我在路徑變量中獲得'我的密鑰'。 – 2014-09-20 08:14:40