Spring Restit Template get方式でデータサーバを送信して空にします。

855 ワード

Spring restit Template類を使ってurlインターフェースをテストする時、getを使ってパラメータサーバ側に要求データが届かないように要求します。
要求コードはこうです。 
Map map = new HashMap<>();

        map.put("p1", "myValue");

        String url = "http://localhost:8080/sayHello";

        String paramedUrl = "http://localhost:8080/sayHello?p1={p1}";

        System.out.println(restTemplate.getForObject(paramedUrl, String.class, map));
urlはparamedUrlと書くべきです。上のurlの形ではありません。一つのブースの役割と似ています。
 @RequestMapping("sayHello")
    @ResponseBody
    public String sayHello(HttpServletRequest httpServletRequest) {

        System.out.println("       :" + httpServletRequest.getParameter("p1"));

        return "helloworld";
    }
urlの変数を使うと、サーバーが空になりますが、paramedUrl変数を使うと正常に値が得られます。