如何传递符号&在@RequestParam?

时间:2013-11-26 00:02:01

标签: java spring url get url-parameters

@RequestMapping(value = {"/hello"}, method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<String> getContent(@RequestParam(value = "url", required = true) String url) {
    System.out.println("My passed url is: " + url);
}

当我这样做时

curl "localhost:8080/hello?url=http://www.test.com/boom/4?utm_source=Google+Places&utm_medium=LLM&utm_campaign=DAC+LLM"

我试图传递的URL作为GET参数在&符号被截断,因为它认为它是另一个GET参数的开头。

My passed url is http://www.test.com/boom/4?utm_source=Google+Places

任何解决方法,或者我应该从GET更改为POST?

1 个答案:

答案 0 :(得分:1)

您应该在前端对字符串进行编码,例如使用encodeURIComponent