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

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]
主站蜘蛛池模板: 炎陵县| 长沙市| 阿拉善盟| 和静县| 安乡县| 中牟县| 屏东县| 禹州市| 库车县| 滕州市| 丹棱县| 三明市| 琼结县| 灌云县| 莎车县| 托克逊县| 白山市| 咸宁市| 东乌| 巴林右旗| 辉南县| 宁晋县| 黔西县| 于都县| 榆林市| 沂源县| 无锡市| 南城县| 九龙坡区| 建德市| 佛山市| 建始县| 射阳县| 文昌市| 平利县| 桦川县| 县级市| 裕民县| 白沙| 隆德县| 社旗县|