-
?传参
举例:
http://localhost:8082/news/asset/getDatas?page=1&keyWord=123&year=2020
注解:
@RequestParam
使用:
@RequestMapping("/getDatas") public String getDatas(@RequestParam("page") int page, @RequestParam("keyWord") String keyWord, @RequestParam("year") String year){ return assetService.getDatas(page,keyWord,year); }
注:@RequestParam可以选择request=false来允许初值为空,但这个值的类型必须为对象,不能为基本类型
-
Restful风格传参
举例:
http://localhost:8082/news/asset/getDatas/1/123/2020
注解:
@PathVariable
使用:
@RequestMapping("/getDatas/{page}/{keyWord}/{year}") public String getDatas(@PathVariable("page") int page,@PathVariable("keyWord") String keyWord,@PathVariable("year") String year){ return assetService.getDatas(page,keyWord,year); }
注:
@PathVariable
绑定的是@RequestMapping
中的变量