@PathVariable和@RequestParam 异同

标签说明示范
@pathVariable(“pageSize”)需要配合rest风格url使用,目的是接收rest Url中的参数 http://127.0.0.1:8082/hello/4
@RequestParam((value = “pageSize”, required = false, defaultValue = “10”))接收普通?后面携带的参数 http://127.0.0.1:8082/hello?pageSize=4
    @RequestMapping(value = "/hello/{pageSize}", method = RequestMethod.GET)
    public String say(@PathVariable("pageSize") String pageSize) {
        return pageSize;
    }

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String say2(@RequestParam(value = "pageSize", required = false, defaultValue = "10") String pageSize) {
        return pageSize;
    }
    原文作者:郭江江
    原文地址: https://segmentfault.com/a/1190000016165633
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞