官术网_书友最值得收藏!

Testing the service on the browser

Open a browser and hit the following URL: http://localhost:8080/product/1.

You should get back the following response:

{"id":1,"name":"Oranges ","catId":2}

Now, try the other service (URL—http://localhost:8080/productIds). What response do you get? An error, as follows:

    There was an unexpected error (type=Bad Request, status=400).
    Required int parameter 'id' is not present

Can you guess why? It is because the service definition that you wrote had a method expecting a request parameter:

@RequestMapping("/productIds")
List<Integer> getProductIds(@RequestParam("id") int id) {

So, the URL is expecting an id and as you did not supply it, it gives an error.

Give the parameter and try  http://localhost:8080/productIds?id=5 again.

You will now get back a correct response:

[6,7,8]
主站蜘蛛池模板: 布拖县| 射洪县| 盘锦市| 扶沟县| 桂平市| 宾阳县| 广州市| 吉首市| 绥江县| 耒阳市| 云霄县| 临漳县| 玉溪市| 五常市| 临沧市| 新干县| 安西县| 南宁市| 牙克石市| 新津县| 水城县| 田东县| 浙江省| 黔东| 浙江省| 永城市| 元江| 建平县| 罗田县| 千阳县| 岐山县| 申扎县| 油尖旺区| 云梦县| 南京市| 子长县| 大邑县| 麻城市| 赣榆县| 龙井市| 泰宁县|