代码之家  ›  专栏  ›  技术社区  ›  SpringUser

如何接收角度应用的get请求中的参数

  •  -2
  • SpringUser  · 技术社区  · 8 年前

    我试图使用querydsl实现搜索过滤器。我的搜索过滤器功能运行良好,但我通过在控制器中给出硬编码值来测试。

    现在我要从角度应用程序中获取搜索参数。在get请求中如何从角度接收此参数 sClientAcctId, sAcctDesc,sInvestigatorName,sClientDeptId

    有人能建议我怎么做吗?

    accountcontroller.java帐户控制器

    @GetMapping("/findAccountData")
    public ResponseEntity<List<Tuple>> populateGridViews(String sClientAcctId, String sAcctDesc,String sInvestigatorName,String sClientDeptId) throws Exception {                  
    
        return  ResponseEntity.ok(accService.populateGridViews(sClientAcctId, sAcctDesc,sInvestigatorName,sClientDeptId));
    

    }

    我试着这样用 @PathVariable 但在这里我需要传递所有参数,然后只有请求是匹配的其他方面我得到404

    我的功能是,如果我没有传递任何参数,那么我需要所有数据,如果我只传递一个参数,那么就按照这样的参数值进行搜索

     @GetMapping("/findAccountData/{clientAcctId}/{acctDesc}/{investigatorName}/{clientDeptId}")
        public ResponseEntity<List<Tuple>>  populateGridViews(
       @PathVariable("clientAcctId") String sClientAcctId,
       @PathVariable("acctDesc") String sAcctDesc,
       @PathVariable("investigatorName") String sInvestigatorName ,
       @PathVariable("clientDeptId") String sClientDeptId) throws Exception { 
    
    2 回复  |  直到 8 年前
        1
  •  1
  •   John    8 年前

    使用其他类型或参数, @RequestParam

    控制器将如下所示

    @GetMapping("/findAccountData/")
    public ResponseEntity<List<Tuple>>
    populateGridViews(@RequestParam("clientAcctId") String
                              sClientAcctId, @RequestParam("acctDesc") String sAcctDesc, @RequestParam("investigatorName") String sInvestigatorName, @RequestParam("clientDeptId") String
                              sClientDeptId) throws Exception {
    }
    

    你可以用 /findAccountData/?clientAcctId=1&acctDesc=desc 传递想要的变量。

        2
  •  -1
  •   Java Team    8 年前

    使用@pathvariable注释从get请求获取任何查询参数值。

    例如:

    @GetMapping("/findAccountData/{clientAcctId}/{acctDesc}/{investigatorName}/{clientDeptId}")
    public ResponseEntity<List<Tuple>> 
    populateGridViews(@PathVariable("clientAcctId") String 
    sClientAcctId,@PathVariable("acctDesc") String sAcctDesc,@PathVariable("investigatorName") String sInvestigatorName,@PathVariable("clientDeptId") String 
    sClientDeptId) throws Exception {