1. ?传参

    举例: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来允许初值为空,但这个值的类型必须为对象,不能为基本类型

  2. 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中的变量

相关文章:

  • 2021-12-24
  • 2022-12-23
  • 2021-08-21
  • 2022-01-04
  • 2022-12-23
  • 2021-11-10
  • 2021-10-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-12
相关资源
相似解决方案