2017-07-19 24 views
1

私のコントローラは、以下のような方法があります。Spring Bootで@RequestParamで設定した文字列をデコードしない方法は?

@ResponseBody 
public String test(@RequestParam("r") String r){ 
String requestURI = request.getQueryString(); 
// What I want: abc+def%2Cfjg 
System.out.println(requestURI.split("=")[1]); 
// This is not what I want: abc def,fjg 
System.out.println(r); 
} 

私は春ブーツがRequestParameterを復号化してはならないことを知らせることができますどのように?つまりスペースに変換するのではなく、%2Cをコンマなどに変換します。

+0

あなたはこれを望んでいるあなたの理由を詳述できますか? – Kayaman

+0

+はURI RFCに基づいて許容される文字であり、リクエストパラメータに属するエンティティを分離する方法としてこれを活用したいと考えています。 –

+0

パラメータを複数の値にしたいのですか?なぜ標準的な方法を使用していないのですか? – Kayaman

答えて

0

あなたのURLをデコードすることができます。

private String decode(String value) { 
    String decoded 
     = URLDecoder.decode(value, StandardCharsets.UTF_8.toString()); 
    return decoded; 
} 

エンコードする場合は、encodeメソッドを使用します。

private String encode(String value) { 
    String encoded = 
     URLEncoder.encode(value, StandardCharsets.UTF_8.toString()); 
    return encoded; 
}